parse_integer_arg() stores through an int pointer, but the caller
passes &params->nr_port, which is a uint8_t and the only member of a
struct octeontx_vdev_init_params on the stack. Parsing nr_port
therefore writes three bytes past the field.

Store a uint8_t and reject a value which does not fit one.

Fixes: f7be70e5130e ("net/octeontx: add net device probe and remove")
Cc: [email protected]

Signed-off-by: Stephen Hemminger <[email protected]>
---
 drivers/net/octeontx/octeontx_ethdev.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/net/octeontx/octeontx_ethdev.c 
b/drivers/net/octeontx/octeontx_ethdev.c
index bde4c2c615..17c40f5708 100644
--- a/drivers/net/octeontx/octeontx_ethdev.c
+++ b/drivers/net/octeontx/octeontx_ethdev.c
@@ -70,14 +70,17 @@ static int
 parse_integer_arg(const char *key __rte_unused,
                const char *value, void *extra_args)
 {
-       int *i = (int *)extra_args;
+       uint8_t *u8 = extra_args;
+       int i;
 
-       *i = atoi(value);
-       if (*i < 0) {
-               octeontx_log_err("argument has to be positive.");
+       i = atoi(value);
+       if (i < 0 || i > UINT8_MAX) {
+               octeontx_log_err("argument has to be positive and fit in a 
byte.");
                return -1;
        }
 
+       *u8 = (uint8_t)i;
+
        return 0;
 }
 
-- 
2.53.0

Reply via email to