Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753300AbdI1Nef (ORCPT ); Thu, 28 Sep 2017 09:34:35 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:59280 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753268AbdI1Ned (ORCPT ); Thu, 28 Sep 2017 09:34:33 -0400 X-Google-Smtp-Source: AOwi7QC98mRQBsgqOj5wnrJEFNhlDKT9R9PvWFvE3wHMfXqKMQPzVZA5pD0BrfrLuzJtEE9HWyPXwQ== From: Seth Forshee To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Shuah Khan Cc: Seth Forshee , linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] selftests/powerpc: Use snprintf to construct DSCR sysfs interface paths Date: Thu, 28 Sep 2017 09:34:26 -0400 Message-Id: <20170928133426.19454-1-seth.forshee@canonical.com> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1375 Lines: 38 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 --- 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