Skip to contentSkip to conversation

tools: ynl: error check scanf() in a sample

PATCH Applied Jakub Kicinski 4 participants 6 messages Aug 28, 2024 – Aug 29, 2024

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 tools: ynl: error check scanf() in a sample

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.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 tools/net/ynl/samples/netdev.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/net/ynl/samples/netdev.c +5 -1
index 3e7b29bd55d5..22609d44c89a 100644
@@ -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;
 }
Signature · 1 line
2.46.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jakub Kicinski

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.

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.

author maintainer
#2 lore raw
Quoted 2 lines · 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..

reviewer
#3 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · 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.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Jakub Kicinski

Le 28/08/2024 à 19:36, Jakub Kicinski a écrit :

Quoted 10 lines

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.

#5 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html