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>
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;