diff mbox series

[net-next] tools: ynl: error check scanf() in a sample

Message ID 20240828173609.2951335-1-kuba@kernel.org (mailing list archive)
State Accepted
Commit 3d8806f37d318b10ddf9fa686821f58bc6301c7b
Delegated to: Netdev Maintainers
Headers show
Series [net-next] tools: ynl: error check scanf() in a sample | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-29--15-00 (tests: 711)

Commit Message

Jakub Kicinski Aug. 28, 2024, 5:36 p.m. UTC
Someone reported on GitHub that the YNL NIPA test is failing
when run locally. The test builds the tools, and it hits:

  netdev.c:82:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  82 | scanf("%d", &ifindex);

I can't repro this on my setups but error seems clear enough.

Link: https://github.com/linux-netdev/nipa/discussions/37
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
CC: donald.hunter@gmail.com
CC: sdf@fomichev.me
CC: martin.lau@kernel.org
CC: ast@kernel.org
CC: nicolas.dichtel@6wind.com
---
 tools/net/ynl/samples/netdev.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Simon Horman Aug. 28, 2024, 6:02 p.m. UTC | #1
On Wed, Aug 28, 2024 at 10:36:09AM -0700, Jakub Kicinski wrote:
> Someone reported on GitHub that the YNL NIPA test is failing
> when run locally. The test builds the tools, and it hits:
> 
>   netdev.c:82:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
>   82 | scanf("%d", &ifindex);
> 
> I can't repro this on my setups but error seems clear enough.
> 
> Link: https://github.com/linux-netdev/nipa/discussions/37
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Thanks, I have a similar patch in my local-queue.

I was able to reproduce the problem on Ubuntu 22.04,
although not on Fedora 40 or Debian Trixie.

Reviewed-by: Simon Horman <horms@kernel.org>
Nicolas Dichtel Aug. 29, 2024, 7:21 a.m. UTC | #2
Le 28/08/2024 à 19:36, Jakub Kicinski a écrit :
> Someone reported on GitHub that the YNL NIPA test is failing
> when run locally. The test builds the tools, and it hits:
> 
>   netdev.c:82:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
>   82 | scanf("%d", &ifindex);
> 
> I can't repro this on my setups but error seems clear enough.
> 
> Link: https://github.com/linux-netdev/nipa/discussions/37
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Jakub Kicinski Aug. 29, 2024, 7:43 p.m. UTC | #3
On Wed, 28 Aug 2024 19:02:46 +0100 Simon Horman wrote:
> I was able to reproduce the problem on Ubuntu 22.04,
> although not on Fedora 40 or Debian Trixie.

Thanks for the info! Made me pause and consider putting the fix
in net, but it's just a warning..
patchwork-bot+netdevbpf@kernel.org Aug. 29, 2024, 7:50 p.m. UTC | #4
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 28 Aug 2024 10:36:09 -0700 you wrote:
> Someone reported on GitHub that the YNL NIPA test is failing
> when run locally. The test builds the tools, and it hits:
> 
>   netdev.c:82:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
>   82 | scanf("%d", &ifindex);
> 
> I can't repro this on my setups but error seems clear enough.
> 
> [...]

Here is the summary with links:
  - [net-next] tools: ynl: error check scanf() in a sample
    https://git.kernel.org/netdev/net-next/c/3d8806f37d31

You are awesome, thank you!
Simon Horman Aug. 29, 2024, 8:52 p.m. UTC | #5
On Thu, Aug 29, 2024 at 12:43:15PM -0700, Jakub Kicinski wrote:
> On Wed, 28 Aug 2024 19:02:46 +0100 Simon Horman wrote:
> > I was able to reproduce the problem on Ubuntu 22.04,
> > although not on Fedora 40 or Debian Trixie.
> 
> Thanks for the info! Made me pause and consider putting the fix
> in net, but it's just a warning..

Yes, it made me pause about sending my version of the patch.
But I think it is worth fixing.
diff mbox series

Patch

diff --git a/tools/net/ynl/samples/netdev.c b/tools/net/ynl/samples/netdev.c
index 3e7b29bd55d5..22609d44c89a 100644
--- a/tools/net/ynl/samples/netdev.c
+++ b/tools/net/ynl/samples/netdev.c
@@ -79,7 +79,10 @@  int main(int argc, char **argv)
 		goto err_close;
 
 	printf("Select ifc ($ifindex; or 0 = dump; or -2 ntf check): ");
-	scanf("%d", &ifindex);
+	if (scanf("%d", &ifindex) != 1) {
+		fprintf(stderr, "Error: unable to parse input\n");
+		goto err_destroy;
+	}
 
 	if (ifindex > 0) {
 		struct netdev_dev_get_req *req;
@@ -119,6 +122,7 @@  int main(int argc, char **argv)
 
 err_close:
 	fprintf(stderr, "YNL: %s\n", ys->err.msg);
+err_destroy:
 	ynl_sock_destroy(ys);
 	return 2;
 }