[PATCH net-next v4 15/17] net: pktgen: num_arg error out in case no valid character is parsed

Peter Seiderer
2025-02-05T13:12:10Z

In num_arg() error out in case no valid character is parsed.

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
Changes v3 -> v4
- new patch (factored out of patch 'net: pktgen: fix access outside of user
given buffer in pktgen_if_write()')
---
net/core/pktgen.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index cb3b732fd0a3..a46eb20edf6c 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -821,6 +821,9 @@ static long num_arg(const char __user *user_buffer, unsigned long maxlen,
if ((c >= '0') && (c <= '9')) {
*num *= 10;
*num += c - '0';
+ } else if (i == 0) {
+ /* no valid character parsed, error out */
+ return -EINVAL;
} else
break;
}
--
2.48.1