[glibc/azanella/ubsan-undef] locate: Fix UB on memcpy call
Adhemerval Zanella
azanella@sourceware.org
Fri Apr 25 19:51:04 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a6d7220313faa8857d82d5fd6bf8485383048e2b
commit a6d7220313faa8857d82d5fd6bf8485383048e2b
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu Apr 17 18:03:16 2025 -0300
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:
---
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 7768a7a7fc..1867c3735b 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;
More information about the Glibc-cvs
mailing list