[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240828173609.2951335-1-kuba@kernel.org>
Date: Wed, 28 Aug 2024 10:36:09 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: davem@...emloft.net
Cc: netdev@...r.kernel.org,
edumazet@...gle.com,
pabeni@...hat.com,
Jakub Kicinski <kuba@...nel.org>,
donald.hunter@...il.com,
sdf@...ichev.me,
martin.lau@...nel.org,
ast@...nel.org,
nicolas.dichtel@...nd.com
Subject: [PATCH net-next] 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.
Link: https://github.com/linux-netdev/nipa/discussions/37
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
CC: donald.hunter@...il.com
CC: sdf@...ichev.me
CC: martin.lau@...nel.org
CC: ast@...nel.org
CC: nicolas.dichtel@...nd.com
---
tools/net/ynl/samples/netdev.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
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;
}
--
2.46.0
Powered by blists - more mailing lists