[PATCH 05/11] locate: Fix UB on memcpy call

Collin Funk collin.funk1@gmail.com
Thu May 8 03:00:25 GMT 2025


Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:

> The ubsan triggers:
>
> UBSAN: Undefined behaviour in programs/charmap.c:908:2 null pointer passed as argument 2, nonnull attribute declared at unknown:0:0
>
> This is not an isseu since size is always '0' in this case.

s/isseu/issue :)

> -
> -      memcpy (new_rules, result->width_rules,
> -	      result->nwidth_rules_max * sizeof (struct width_rule));
> +      if (result->width_rules != NULL)
> +	memcpy (new_rules, result->width_rules,
> +		result->nwidth_rules_max * sizeof (struct width_rule));
[...]

This should be well defined in the future as long as the size is always
zero [1].

But I guess since it is still undefined, your change is correct...

Collin

[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf


More information about the Libc-alpha mailing list