diskutil: ensure we have enough room to not write past end
authorJens Axboe <axboe@kernel.dk>
Wed, 7 Jun 2017 16:45:46 +0000 (10:45 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Jun 2017 16:45:46 +0000 (10:45 -0600)
gcc 7.1 triggers this warning:

diskutil.c: In function ‘find_block_dir’:
diskutil.c:371:22: warning: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
   sprintf(full_path, "%s/%s", path, dir->d_name);
                      ^~~~~~~
In file included from /usr/include/stdio.h:936:0,
                 from diskutil.c:1:

Ensure that it's 256+1 in length.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diskutil.c

index dca3748..9767ea2 100644 (file)
@@ -363,7 +363,7 @@ static int find_block_dir(int majdev, int mindev, char *path, int link_ok)
                return 0;
 
        while ((dir = readdir(D)) != NULL) {
-               char full_path[256];
+               char full_path[257];
 
                if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
                        continue;