https://lists.gnu.org/archive/html/bug-texinfo/2023-11/msg00001.html
From 12ad80f3a1cfa78c8a7b3a45458df7e07251317d Mon Sep 17 00:00:00 2001
From: Gavin Smith
Date: Sat, 4 Nov 2023 10:38:48 +0000
Subject: [PATCH 3/5] * info/scan.c (write_tag_contents): Check if added text
is of zero length in order to avoid subsequently calling memcpy with a null
source argument. Report with -fsanitize=undefined on amd64 from Sam James
.
---
ChangeLog | 7 +++++++
info/scan.c | 4 ++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3d13a15517..efbb3b22d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-11-04 Gavin Smith
+
+ * info/scan.c (write_tag_contents): Check if added text is of
+ zero length in order to avoid subsequently calling memcpy with
+ a null source argument. Report with -fsanitize=undefined on amd64
+ from Sam James .
+
2023-10-25 Eli Zaretskii
* tp/Texinfo/XS/xspara.c (xspara__add_next): Do not pass
diff --git a/info/scan.c b/info/scan.c
index d6183ae9ae..bdf272f9bf 100644
--- a/info/scan.c
+++ b/info/scan.c
@@ -925,11 +925,11 @@ write_extra_bytes_to_output (char *input, long n)
}
/* Like write_extra_bytes_to_output, but writes bytes even when
- preprocess_nodes=Off. */
+ preprocess_nodes=Off. Note n could be 0 for an index tag. */
static void
write_tag_contents (char *input, long n)
{
- if (rewrite_p)
+ if (rewrite_p && n > 0)
{
text_buffer_add_string (&output_buf, input, n);
output_bytes_difference -= n;
--
2.42.1