summaryrefslogtreecommitdiff
path: root/sys-apps/texinfo/files/7.1/0003-info-scan.c-write_tag_contents-Check-if-added-text-i.patch
blob: b3fbc85f461bcb0f36415105be68d2698ac15c05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
https://lists.gnu.org/archive/html/bug-texinfo/2023-11/msg00001.html

From 12ad80f3a1cfa78c8a7b3a45458df7e07251317d Mon Sep 17 00:00:00 2001
From: Gavin Smith <gavinsmith0123@gmail.com>
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
 <sam@gentoo.org>.

---
 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 <gavinsmith0123@gmail.com>
+
+	* 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 <sam@gentoo.org>.
+
 2023-10-25  Eli Zaretskii <eliz@gnu.org>
 
 	* 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