[PATCH v2 1/1] event/octeontx: resolve possible integer overflow

Stephen Hemminger stephen at networkplumber.org
Wed Oct 23 18:16:13 CEST 2024


On Wed, 23 Oct 2024 12:45:46 +0530
Hanumanth Pothula <hpothula at marvell.com> wrote:

>  static int
> -ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque)
> +ssovf_parsekv(const char *key, const char *value, void *opaque)
>  {
> -	int *flag = opaque;
> -	*flag = !!atoi(value);
> +	uint8_t *flag = opaque;
> +	uint64_t v;
> +	char *end;
> +
> +	errno = 0;
> +	v = (uint8_t)strtoul(value, &end, 0);

Cast will cause truncation of large values.

Maybe:
	v = strtoul(value, &end, 0);
	if (errno != 0 || value == end || *end != '\0' || v > UINT8_MAX) {
...


> +	if ((errno != 0) || (value == end) || *end != '\0') {
> +		ssovf_log_err("invalid %s value %s", key, value);
> +		return -EINVAL;
> +	}
> +
> +	*flag = !!v;
>  	return 0;
>  }


More information about the dev mailing list