net/txgbe: validate numeric devargs
PATCH 1/1 net/txgbe: validate numeric devargs
Be more careful about validating devargs numeric values. Don't silently truncate to 16 bits, and check for empty string or trailing garbage.
Fixes f611dada1af8 ("net/txgbe: update link setup process of backplane NICs")
Signed-off-by Stephen Hemminger <[email protected]>
--- drivers/net/txgbe/txgbe_ethdev.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/txgbe/txgbe_ethdev.c +10 -4
@@ -450,15 +450,21 @@ static int txgbe_handle_devarg(__rte_unused const char *key, const char *value, void *extra_args) { - uint16_t *n = extra_args; + uint16_t *arg = extra_args; +char *endp; +unsigned long num;if (value ==NULL || extra_args ==NULL )return -EINVAL ; - *n = (uint16_t )strtoul (value,NULL ,10 ); -if (*n ==USHRT_MAX && errno ==ERANGE ) -return -1 ; + errno =0 ; + num =strtoul (value, &endp,10 ); +if (*value =='\0' || *endp !='\0' ) +return -EINVAL ; +if (num >UINT16_MAX || errno ==ERANGE ) +return -ERANGE ; + *arg = (uint16_t )num;return 0 ; }
Signature · 1 line
2.53.0