Whamcloud - gitweb
misc: fix problems with strncat
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 18 Jul 2014 22:54:07 +0000 (15:54 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 25 Jul 2014 11:21:47 +0000 (07:21 -0400)
The third argument to strncat is the maximum number of characters to
copy out of the second argument; it is not the maximum length of the
first argument.

Therefore, code in a check just in case we ever find a /sys/block/X
path long enough to hit the end of the buffer.  FWIW the longest path
I could find on my machine was 133 bytes.

Fixes-Coverity-Bug: 1252003
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/mk_hugefiles.c

index 41280f0..6bc25e6 100644 (file)
@@ -188,7 +188,9 @@ static blk64_t get_partition_start(const char *device_name)
        cp = search_sysfs_block(st.st_rdev, path);
        if (!cp)
                return 0;
-       strncat(path, "/start", SYSFS_PATH_LEN-1);
+       if (strlen(path) > SYSFS_PATH_LEN - sizeof("/start"))
+               return 0;
+       strcat(path, "/start");
        f = fopen(path, "r");
        if (!f)
                return 0;