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

Adhemerval Zanella adhemerval.zanella@linaro.org
Wed May 7 14:17:23 GMT 2025


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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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;
-- 
2.43.0



More information about the Libc-alpha mailing list