]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
locate: Fix UB on memcpy call
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 17 Apr 2025 21:03:16 +0000 (18:03 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 13:41:34 +0000 (10:41 -0300)
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.

locale/programs/charmap.c

index 58433c8c5bdd27e1bdadb929c0129be39ff80f6b..07d406e12f085206976dde38e53a193c248d210f 100644 (file)
@@ -904,9 +904,9 @@ number of bytes for byte sequence of beginning and end of range not the same: %d
        (struct width_rule *) obstack_alloc (&result->mem_pool,
                                             (new_size
                                              * sizeof (struct width_rule)));
-
-      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));
 
       result->width_rules = new_rules;
       result->nwidth_rules_max = new_size;