linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/powerpc: Use snprintf to construct DSCR sysfs interface paths
@ 2017-09-28 13:34 Seth Forshee
  2017-10-08  8:43 ` Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Seth Forshee @ 2017-09-28 13:34 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, Shuah Khan
  Cc: Seth Forshee, linuxppc-dev, linux-kselftest, linux-kernel

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>
---
 tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
index 17fb1b43c320..1899bd85121f 100644
--- a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
+++ b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
@@ -53,6 +53,8 @@ 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"))
@@ -60,7 +62,9 @@ static int check_all_cpu_dscr_defaults(unsigned long val)
 		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;
 
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: selftests/powerpc: Use snprintf to construct DSCR sysfs interface paths
  2017-09-28 13:34 [PATCH] selftests/powerpc: Use snprintf to construct DSCR sysfs interface paths Seth Forshee
@ 2017-10-08  8:43 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2017-10-08  8:43 UTC (permalink / raw)
  To: Seth Forshee, Benjamin Herrenschmidt, Paul Mackerras, Shuah Khan
  Cc: Seth Forshee, linuxppc-dev, linux-kernel, linux-kselftest

On Thu, 2017-09-28 at 13:34:26 UTC, Seth Forshee wrote:
> 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>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/06755a871314c7443a89c09650cdb3

cheers

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-08  8:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-28 13:34 [PATCH] selftests/powerpc: Use snprintf to construct DSCR sysfs interface paths Seth Forshee
2017-10-08  8:43 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).