summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2023-01-13 16:27:54 -0600
committerEric Blake <eblake@redhat.com>2023-01-13 16:33:49 -0600
commita886ea40a29a08954ff80772e267828a1d440cc9 (patch)
tree12735a422564469ae816fef43b15275919c0d392
parentdd434e3e958b3cebde954d66010919a40665812e (diff)
downloadm4-branch-1.4.tar.gz
output: Avoid tickling UBSAN with memcpy(dest, NULL, 0)branch-1.4
Even though all libc handle it sanely (because size 0 says there is nothing to copy), NULL is not a valid source pointer per a strict reading of C, so UBSAN flags it: +output.c:511:9: runtime error: null pointer passed as argument 2, which is declared to never be null * src/output.c (make_room_for): Skip no-op memcpy. Fixes: https://savannah.gnu.org/support/index.php?110809 Reported-by: Sam James
-rw-r--r--src/output.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/output.c b/src/output.c
index 956089b1..6dc8280a 100644
--- a/src/output.c
+++ b/src/output.c
@@ -508,7 +508,8 @@ make_room_for (int length)
{
char *buffer = output_diversion->u.buffer;
output_diversion->u.buffer = xcharalloc ((size_t) wanted_size);
- memcpy (output_diversion->u.buffer, buffer, output_diversion->used);
+ if (output_diversion->used)
+ memcpy (output_diversion->u.buffer, buffer, output_diversion->used);
free (buffer);
}