Commit f08fee55 by Christian Brauner Committed by Serge Hallyn

Do not use strlen() on non-null terminated buffer

parent 61111832
...@@ -1989,7 +1989,7 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc ...@@ -1989,7 +1989,7 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
char newpath[MAXPATHLEN]; char newpath[MAXPATHLEN];
int fd, ret, n = 0, v = 0; int fd, ret, n = 0, v = 0;
bool bret = false; bool bret = false;
size_t len; size_t len, difflen;
if (container_disk_lock(c0)) if (container_disk_lock(c0))
return false; return false;
...@@ -2072,19 +2072,22 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc ...@@ -2072,19 +2072,22 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
/* mmap()ed memory is only \0-terminated when it is not /* mmap()ed memory is only \0-terminated when it is not
* a multiple of a pagesize. Hence, we'll use memmem(). */ * a multiple of a pagesize. Hence, we'll use memmem(). */
if ((del = memmem(buf, fbuf.st_size, newpath, len))) { if ((del = memmem(buf, fbuf.st_size, newpath, len))) {
/* remove container entry */ /* remove container entry */
memmove(del, del + len, strlen(del) - len + 1); if (del != buf + fbuf.st_size - len) {
difflen = fbuf.st_size - (del-buf);
munmap(buf, fbuf.st_size); memmove(del, del + len, strnlen(del, difflen) - len);
}
if (ftruncate(fd, fbuf.st_size - len) < 0) {
SYSERROR("Failed to truncate file %s", path); munmap(buf, fbuf.st_size);
close(fd);
goto out; if (ftruncate(fd, fbuf.st_size - len) < 0) {
} SYSERROR("Failed to truncate file %s", path);
} else { close(fd);
munmap(buf, fbuf.st_size); goto out;
}
} else {
munmap(buf, fbuf.st_size);
} }
close(fd); close(fd);
......
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