From: Adhemerval Zanella Date: Thu, 17 Apr 2025 21:03:16 +0000 (-0300) Subject: locate: Fix UB on memcpy call X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59d419cf1252982a2e0277601280279245ffd22e;p=thirdparty%2Fglibc.git locate: Fix UB on memcpy call 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. --- diff --git a/locale/programs/charmap.c b/locale/programs/charmap.c index 58433c8c5b..07d406e12f 100644 --- a/locale/programs/charmap.c +++ b/locale/programs/charmap.c @@ -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;