[PATCH v2 7/8] net/rnp add devargs runtime parsing functions

Stephen Hemminger stephen at networkplumber.org
Wed Aug 2 18:15:57 CEST 2023


On Wed,  2 Aug 2023 08:11:05 +0000
Wenbo Cao <caowenbo at mucse.com> wrote:

> +	if (strcmp(key, RNP_HW_MAC_LOOPBACK_ARG) == 0) {
> +		uint16_t *n = extra_args;
> +		*n = (uint16_t)strtoul(value, NULL, 10);
> +		if (*n == USHRT_MAX && errno == ERANGE)
> +			return -1;

You should be using unsigned long for n here
and no cast. Otherwise a large buggy argument would not be caught.

Something like:
	if (strcmp(key, RNP_HW_MAC_LOOPBACK_ARG) == 0) {
		unsigned long n;
		uint16_t *result = extra_args;
		n = strtoul(value, NULL, 10);
		if (n > UINT16_MAX) {
			XXXLOG("invalid loopback arg"...
			return -1;
		}
		*result = n;



More information about the dev mailing list