Skip to content

Commit

Permalink
selftests/powerpc: Use snprintf to construct DSCR sysfs interface paths
Browse files Browse the repository at this point in the history
Currently sprintf is used, and while paths should never exceed
the size of the buffer it is theoretically possible since
dirent.d_name is 256 bytes. As a result this trips
-Wformat-overflow, and since the test is built with -Wall -Werror
the causes the build to fail. Switch to using snprintf and skip
any paths which are too long for the filename buffer.

Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Seth Forshee authored and Michael Ellerman committed Oct 6, 2017
1 parent 186b8f1 commit 06755a8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
Original file line number Diff line number Diff line change
@@ -53,14 +53,18 @@ static int check_all_cpu_dscr_defaults(unsigned long val)
}

while ((dp = readdir(sysfs))) {
int len;

if (!(dp->d_type & DT_DIR))
continue;
if (!strcmp(dp->d_name, "cpuidle"))
continue;
if (!strstr(dp->d_name, "cpu"))
continue;

sprintf(file, "%s%s/dscr", CPU_PATH, dp->d_name);
len = snprintf(file, LEN_MAX, "%s%s/dscr", CPU_PATH, dp->d_name);
if (len >= LEN_MAX)
continue;
if (access(file, F_OK))
continue;

0 comments on commit 06755a8

Please sign in to comment.