Unverified Commit 02882d83 by Stéphane Graber Committed by GitHub

Merge pull request #3687 from brauner/2021-02-19/fixes

lsm: fixes
parents f43ed6a0 ba9055c9
......@@ -455,12 +455,15 @@ int fd_to_buf(int fd, char **buf, size_t *length)
bytes_read = lxc_read_nointr(fd, chunk, sizeof(chunk));
if (bytes_read < 0)
return 0;
return -errno;
if (!bytes_read)
break;
copy = must_realloc(old, (*length + bytes_read) * sizeof(*old));
copy = realloc(old, (*length + bytes_read) * sizeof(*old));
if (!copy)
return ret_errno(ENOMEM);
memcpy(copy + *length, chunk, bytes_read);
*length += bytes_read;
}
......
......@@ -430,15 +430,21 @@ error:
static char *apparmor_process_label_get(struct lsm_ops *ops, pid_t pid)
{
int label_fd;
__do_close int fd_label = -EBADF;
__do_free char *label = NULL;
int ret;
size_t len;
label_fd = __apparmor_process_label_open(ops, pid, O_RDONLY, false);
if (label_fd < 0)
fd_label = __apparmor_process_label_open(ops, pid, O_RDONLY, false);
if (fd_label < 0)
return NULL;
ret = fd_to_buf(fd_label, &label, &len);
if (ret < 0)
return NULL;
fd_to_buf(label_fd, &label, &len);
if (len == 0)
return NULL;
len = strcspn(label, "\n \t");
if (len)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment