gpu-manager: increase string storage on stack for path names
gcc emits the following warnings when building up path names:
gpu-manager.c: In function ‘count_connected_outputs’:
gpu-manager.c:919:31: warning: ‘%s’ directive writing up to 255 bytes into a region of size 49 [-Wformat-overflow=]
sprintf(name, "%s/%s/status", drm_dir, dp->d_name);
^~
gpu-manager.c:919:13: note: ‘sprintf’ output 9 or more bytes (assuming 264) into a destination of size 50
sprintf(name, "%s/%s/status", drm_dir, dp->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gpu-manager.c: In function ‘has_driver_connected_outputs’:
gpu-manager.c:957:42: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 19 [-Wformat-truncation=]
snprintf(path, sizeof(path), "%s/%s", dri_dir, dir_entry->d_name);
^~
gpu-manager.c:957:9: note: ‘snprintf’ output 2 or more bytes (assuming 257) into a destination of size 20
snprintf(path, sizeof(path), "%s/%s", dri_dir, dir_entry->d_name);
These warnings are based on assuming the maximum possible length for the
d_name field in the struct dirent records. The allocated space is likely
sufficient for the directory names that are expected to occur, but it
doesn't hurt to allocate a few hundred more bytes to definitively prevent
overflowing the buffer.
Rather than accommodating just the maximum length of d_name, just allocate
PATH_MAX bytes for the relevant path names, in case other aspects of the
format string change in the future. As a measure of additional paranoia,
use snprintf for both paths and explicitly NUL-terminate the buffer just
in case the format string and its arguments somehow manage to evaluate to
a string longer than PATH_MAX.
Signed-off-by: Daniel Dadap <email address hidden>
Reviewed-by: Aaron Plattner <email address hidden>