lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210709063741.355325-2-chenlifu@huawei.com>
Date:   Fri, 9 Jul 2021 14:37:41 +0800
From:   Chen Lifu <chenlifu@...wei.com>
To:     <pbonzini@...hat.com>, <shuah@...nel.org>, <bgardon@...gle.com>,
        <wangyanan55@...wei.com>, <axelrasmussen@...gle.com>,
        <drjones@...hat.com>, <chenlifu@...wei.com>, <seanjc@...gle.com>,
        <vkuznets@...hat.com>, <dwmw@...zon.co.uk>,
        <joao.m.martins@...cle.com>, <yangyingliang@...wei.com>,
        <kvm@...r.kernel.org>, <linux-kselftest@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>
Subject: [PATCH -next 2/2] selftests: Fix fscanf warning

Compile selftests occurs the following warnings:
make -C tools/testing/selftests
...

lib/test_util.c: In function ‘get_trans_hugepagesz’:
lib/test_util.c:138:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
  138 |  fscanf(f, "%ld", &size);
      |  ^~~~~~~~~~~~~~~~~~~~~~~
x86_64/mmio_warning_test.c: In function ‘get_warnings_count’:
x86_64/mmio_warning_test.c:85:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
   85 |  fscanf(f, "%d", &warnings);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~
x86_64/xen_shinfo_test.c: In function ‘get_run_delay’:
x86_64/xen_shinfo_test.c:109:9: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
  109 |         fscanf(fp, "%ld %ld ", &val[0], &val[1]);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
steal_time.c: In function ‘get_run_delay’:
steal_time.c:228:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
  228 |  fscanf(fp, "%ld %ld ", &val[0], &val[1]);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check the return value of ‘fscanf’ to fix it.

Signed-off-by: Chen Lifu <chenlifu@...wei.com>
---
 tools/testing/selftests/kvm/lib/test_util.c            | 3 ++-
 tools/testing/selftests/kvm/steal_time.c               | 3 ++-
 tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 3 ++-
 tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c   | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
index af1031fed97f..02ed0d5c3aa5 100644
--- a/tools/testing/selftests/kvm/lib/test_util.c
+++ b/tools/testing/selftests/kvm/lib/test_util.c
@@ -135,7 +135,8 @@ size_t get_trans_hugepagesz(void)
 	f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r");
 	TEST_ASSERT(f != NULL, "Error in opening transparent_hugepage/hpage_pmd_size");
 
-	fscanf(f, "%ld", &size);
+	if (fscanf(f, "%ld", &size) != 1)
+		size = 0;
 	fclose(f);
 
 	return size;
diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selftests/kvm/steal_time.c
index b0031f2d38fd..18f231c45a12 100644
--- a/tools/testing/selftests/kvm/steal_time.c
+++ b/tools/testing/selftests/kvm/steal_time.c
@@ -225,7 +225,8 @@ static long get_run_delay(void)
 
 	sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
 	fp = fopen(path, "r");
-	fscanf(fp, "%ld %ld ", &val[0], &val[1]);
+	if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) != 2)
+		val[1] = 0;
 	fclose(fp);
 
 	return val[1];
diff --git a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c
index e6480fd5c4bd..e770037e5cc9 100644
--- a/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c
+++ b/tools/testing/selftests/kvm/x86_64/mmio_warning_test.c
@@ -82,7 +82,8 @@ int get_warnings_count(void)
 	FILE *f;
 
 	f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
-	fscanf(f, "%d", &warnings);
+	if (fscanf(f, "%d", &warnings) != 1)
+		warnings = 0;
 	fclose(f);
 
 	return warnings;
diff --git a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
index 117bf49a3d79..6efda86083f1 100644
--- a/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
+++ b/tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c
@@ -106,7 +106,8 @@ static long get_run_delay(void)
 
         sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
         fp = fopen(path, "r");
-        fscanf(fp, "%ld %ld ", &val[0], &val[1]);
+	if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) != 2)
+		val[1] = 0;
         fclose(fp);
 
         return val[1];
-- 
2.32.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ