Skip to content

Commit ae62cf5

Browse files
jhovoldgregkh
authored andcommitted
staging: greybus: loopback_test: fix potential path truncations
Newer GCC warns about possible truncations of two generated path names as we're concatenating the configurable sysfs and debugfs path prefixes with a filename and placing the results in buffers of the same size as the maximum length of the prefixes. snprintf(d->name, MAX_STR_LEN, "gb_loopback%u", dev_id); snprintf(d->sysfs_entry, MAX_SYSFS_PATH, "%s%s/", t->sysfs_prefix, d->name); snprintf(d->debugfs_entry, MAX_SYSFS_PATH, "%sraw_latency_%s", t->debugfs_prefix, d->name); Fix this by separating the maximum path length from the maximum prefix length and reducing the latter enough to fit the generated strings. Note that we also need to reduce the device-name buffer size as GCC isn't smart enough to figure out that we ever only used MAX_STR_LEN bytes of it. Fixes: 6b0658f ("greybus: tools: Add tools directory to greybus repo and add loopback") Signed-off-by: Johan Hovold <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f160238 commit ae62cf5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/staging/greybus/tools/loopback_test.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <signal.h>
2020

2121
#define MAX_NUM_DEVICES 10
22+
#define MAX_SYSFS_PREFIX 0x80
2223
#define MAX_SYSFS_PATH 0x200
2324
#define CSV_MAX_LINE 0x1000
2425
#define SYSFS_MAX_INT 0x20
@@ -67,7 +68,7 @@ struct loopback_results {
6768
};
6869

6970
struct loopback_device {
70-
char name[MAX_SYSFS_PATH];
71+
char name[MAX_STR_LEN];
7172
char sysfs_entry[MAX_SYSFS_PATH];
7273
char debugfs_entry[MAX_SYSFS_PATH];
7374
struct loopback_results results;
@@ -93,8 +94,8 @@ struct loopback_test {
9394
int stop_all;
9495
int poll_count;
9596
char test_name[MAX_STR_LEN];
96-
char sysfs_prefix[MAX_SYSFS_PATH];
97-
char debugfs_prefix[MAX_SYSFS_PATH];
97+
char sysfs_prefix[MAX_SYSFS_PREFIX];
98+
char debugfs_prefix[MAX_SYSFS_PREFIX];
9899
struct timespec poll_timeout;
99100
struct loopback_device devices[MAX_NUM_DEVICES];
100101
struct loopback_results aggregate_results;
@@ -907,10 +908,10 @@ int main(int argc, char *argv[])
907908
t.iteration_max = atoi(optarg);
908909
break;
909910
case 'S':
910-
snprintf(t.sysfs_prefix, MAX_SYSFS_PATH, "%s", optarg);
911+
snprintf(t.sysfs_prefix, MAX_SYSFS_PREFIX, "%s", optarg);
911912
break;
912913
case 'D':
913-
snprintf(t.debugfs_prefix, MAX_SYSFS_PATH, "%s", optarg);
914+
snprintf(t.debugfs_prefix, MAX_SYSFS_PREFIX, "%s", optarg);
914915
break;
915916
case 'm':
916917
t.mask = atol(optarg);
@@ -961,10 +962,10 @@ int main(int argc, char *argv[])
961962
}
962963

963964
if (!strcmp(t.sysfs_prefix, ""))
964-
snprintf(t.sysfs_prefix, MAX_SYSFS_PATH, "%s", sysfs_prefix);
965+
snprintf(t.sysfs_prefix, MAX_SYSFS_PREFIX, "%s", sysfs_prefix);
965966

966967
if (!strcmp(t.debugfs_prefix, ""))
967-
snprintf(t.debugfs_prefix, MAX_SYSFS_PATH, "%s", debugfs_prefix);
968+
snprintf(t.debugfs_prefix, MAX_SYSFS_PREFIX, "%s", debugfs_prefix);
968969

969970
ret = find_loopback_devices(&t);
970971
if (ret)

0 commit comments

Comments
 (0)