]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tac: avoid out of bounds access
authorPádraig Brady <P@draigBrady.com>
Wed, 15 Jan 2025 17:42:55 +0000 (17:42 +0000)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Jan 2025 17:42:55 +0000 (17:42 +0000)
This was flagged on CheriBSD on ARM Morello with the error:
"In-address space security exception (core dumped)"
triggered with: tac -s '' /dev/null

* src/tac.c (main): Ensure we don't read beyond the
end of the supplied optarg.

src/tac.c

index e4aac77fe1b3874295041f51d42f6e025d11720c..f086f5345151e3947dd055abe581df59bc870113 100644 (file)
--- a/src/tac.c
+++ b/src/tac.c
@@ -553,7 +553,7 @@ main (int argc, char **argv)
   G_buffer = xmalloc (G_buffer_size);
   if (sentinel_length)
     {
-      memcpy (G_buffer, separator, sentinel_length + 1);
+      memcpy (G_buffer, separator, sentinel_length + !!*separator);
       G_buffer += sentinel_length;
     }
   else