Unverified Commit 5b29b6a7 by Lukasz Jagiello Committed by Christian Brauner

lseek - integer overflow

The issue was introduced in PR (https://github.com/lxc/lxc/pull/1705): Previous code: ``` if (lseek(fd, size, SEEK_SET) < 0) { SYSERROR("Error seeking to set new loop file size"); close(fd); return -1; } ``` New code: ``` int fd, ret; [...] ret = lseek(fd, size, SEEK_SET); if (ret < 0) { SYSERROR("Failed to seek to set new loop file size for loop " "file \"%s\"", path); close(fd); return -1; } ``` Based on http://man7.org/linux/man-pages/man2/lseek.2.html: > Upon successful completion, lseek() returns the resulting offset > location as measured in bytes from the beginning of the file. So in this case value of `size` and `size` is `uint64_t`. This fix change declaration of `ret`, but it can be fixed in other ways. Let me know what works for you. This PR fix issues (https://github.com/lxc/lxc/issues/1872). Signed-off-by: 's avatarLukasz Jagiello <lukasz@wikia-inc.com>
parent 56e193a6
...@@ -297,6 +297,7 @@ int loop_umount(struct lxc_storage *bdev) ...@@ -297,6 +297,7 @@ int loop_umount(struct lxc_storage *bdev)
static int do_loop_create(const char *path, uint64_t size, const char *fstype) static int do_loop_create(const char *path, uint64_t size, const char *fstype)
{ {
int fd, ret; int fd, ret;
off_t ret_size;
char cmd_output[MAXPATHLEN]; char cmd_output[MAXPATHLEN];
const char *cmd_args[2] = {fstype, path}; const char *cmd_args[2] = {fstype, path};
...@@ -307,8 +308,8 @@ static int do_loop_create(const char *path, uint64_t size, const char *fstype) ...@@ -307,8 +308,8 @@ static int do_loop_create(const char *path, uint64_t size, const char *fstype)
return -1; return -1;
} }
ret = lseek(fd, size, SEEK_SET); ret_size = lseek(fd, size, SEEK_SET);
if (ret < 0) { if (ret_size < 0) {
SYSERROR("Failed to seek to set new loop file size for loop " SYSERROR("Failed to seek to set new loop file size for loop "
"file \"%s\"", path); "file \"%s\"", path);
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