Skip to contentSkip to conversation

indent: fix CVE-2023-40305

PATCH New Gyorgy Sarvari 1 participant 3 messages Sep 27, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 indent: fix CVE-2023-40305

From: Yogita Urade <[email protected]>

GNU indent 2.2.13 has a heap-based buffer overflow in search_brace in indent.c via a crafted file.

Reference:
https://savannah.gnu.org/bugs/index.php?64503

(cherry picked from commit 7da6cb848bc42b3e6bd5d2b37b52ba75510a6ca0)
---
 .../indent/indent/CVE-2023-40305_0001.patch   | 4196 ++++++++++++++++
 .../indent/indent/CVE-2023-40305_0002.patch   | 4254 +++++++++++++++++
 .../recipes-extended/indent/indent_2.2.12.bb  |    2 +
 3 files changed, 8452 insertions(+)
 create mode 100644 meta-oe/recipes-extended/indent/indent/CVE-2023-40305_0001.patch
 create mode 100644 meta-oe/recipes-extended/indent/indent/CVE-2023-40305_0002.patch
meta-oe/recipes-extended/indent/indent/CVE-2023-40305_0001.patch new file +4196 -0
new file mode 100644
index 0000000000..367202e3c5
@@ -0,0 +1,4196 @@
+From df4ab2d19e247d059e0025789ba513418073ab6f Mon Sep 17 00:00:00 2001
+From: Petr Písař <[email protected]>
+Date: Thu, 19 Oct 2023 07:36:32 +0000
+Subject: [PATCH] Fix an out-of-buffer read in search_brace()/lexi() on an
+ condition without parentheses followed with an overlong comment
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Reproducer:
+
+$ hexdump -C /tmp/short
+00000000  69 66 20 30 3b 65 6c 73  65 2f 2a 0a 0a 0a 0a 0a  |if 0;else/*.....|
+00000010  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
+*
+00000800  0a 0a 2a 2f 78 0a                                 |..*/x.|
+00000806
+
+$ valgrind -- ./indent -o /dev/null /tmp/short
+[...]
+==21830== Invalid read of size 1
+==21830==    at 0x40586A: lexi (lexi.c:251)
+==21830==    by 0x40198C: search_brace (indent.c:387)
+==21830==    by 0x401CC2: indent_main_loop (indent.c:548)
+==21830==    by 0x402298: indent (indent.c:758)
+==21830==    by 0x402941: indent_single_file (indent.c:1003)
+==21830==    by 0x402A0F: indent_all (indent.c:1041)
+==21830==    by 0x402BC5: main (indent.c:1122)
+==21830==  Address 0x4ab2210 is 0 bytes inside a block of size 2,048 free'd
+==21830==    at 0x4847A40: realloc (vg_replace_malloc.c:1649)
+==21830==    by 0x408BC0: xrealloc (globs.c:64)
+==21830==    by 0x40BF03: need_chars (handletoken.c:89)
+==21830==    by 0x401433: sw_buffer (indent.c:149)
+==21830==    by 0x401973: search_brace (indent.c:380)
+==21830==    by 0x401CC2: indent_main_loop (indent.c:548)
+==21830==    by 0x402298: indent (indent.c:758)
+==21830==    by 0x402941: indent_single_file (indent.c:1003)
+==21830==    by 0x402A0F: indent_all (indent.c:1041)
+==21830==    by 0x402BC5: main (indent.c:1122)
+==21830==  Block was alloc'd at
+==21830==    at 0x4847A40: realloc (vg_replace_malloc.c:1649)
+==21830==    by 0x408BC0: xrealloc (globs.c:64)
+==21830==    by 0x40BF03: need_chars (handletoken.c:89)
+==21830==    by 0x401696: search_brace (indent.c:281)
+==21830==    by 0x401CC2: indent_main_loop (indent.c:548)
+==21830==    by 0x402298: indent (indent.c:758)
+==21830==    by 0x402941: indent_single_file (indent.c:1003)
+==21830==    by 0x402A0F: indent_all (indent.c:1041)
+==21830==    by 0x402BC5: main (indent.c:1122)
+
+The cause was that need_chars(&save_com, ...) could reallocate save_com.ptr
+pointer keeping a dangling copy of that pointer saved to buf_ptr
+a line above.
+
+Related to CVE-2023-40305
+
+Signed-off-by: Petr Písař <[email protected]>
+
+CVE: CVE-2023-40305
+
+Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/indent.git/commit/?id=df4ab2d19e247d059e0025789ba513418073ab6f]
+
+Signed-off-by: Yogita Urade <[email protected]>
+---
+ regression/TEST                             |    3 +-
+ regression/input/comment-heap-overread.c    | 2040 ++++++++++++++++++
+ regression/standard/comment-heap-overread.c | 2042 +++++++++++++++++++
+ src/indent.c                                |    2 +-
+ 4 files changed, 4085 insertions(+), 2 deletions(-)
+ create mode 100644 regression/input/comment-heap-overread.c
+ create mode 100644 regression/standard/comment-heap-overread.c
+
+diff --git a/regression/TEST b/regression/TEST
+index 56f41d9..a7a6747 100755
+--- a/regression/TEST
++++ b/regression/TEST
+@@ -37,7 +37,8 @@ BUGS="case-label.c one-line-1.c one-line-2.c one-line-3.c \
+         one-line-4.c struct-decl.c sizeof-in-while.c line-break-comment.c \
+         macro.c enum.c elif.c nested.c wrapped-string.c minus_predecrement.c \
+         bug-gnu-33364.c float-constant-suffix.c block-comments.c \
+-        no-forced-nl-in-block-init.c hexadecimal_float.c"
++        no-forced-nl-in-block-init.c hexadecimal_float.c \
++        comment-heap-overread.c"
+
+ INDENTSRC="args.c backup.h backup.c dirent_def.h globs.c indent.h \
+         indent.c indent_globs.h io.c lexi.c memcpy.c parse.c pr_comment.c \
+diff --git a/regression/input/comment-heap-overread.c b/regression/input/comment-heap-overread.c
+new file mode 100644
+index 0000000..5b0b172
+--- /dev/null
++++ b/regression/input/comment-heap-overread.c
+@@ -0,0 +1,2040 @@
++if 0;else/*
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++*/x
+diff --git a/regression/standard/comment-heap-overread.c b/regression/standard/comment-heap-overread.c
+new file mode 100644
+index 0000000..e601fb4
+--- /dev/null
++++ b/regression/standard/comment-heap-overread.c
+@@ -0,0 +1,2042 @@
++if 0;
++else				/*
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
++
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

meta-oe/recipes-extended/indent/indent/CVE-2023-40305_0002.patch new file +4254 -0

4,254 lines not on this page · raw message

meta-oe/recipes-extended/indent/indent_2.2.12.bb +2 -0
index 7847b535b3..2326f47b44 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#1 lore raw

PATCH 2/3 indent: fix CVE-2024-0911

From: hongxu <[email protected]>

Backport a fix from upstream to resolve CVE-2024-0911

https://git.savannah.gnu.org/git/indent.git feb2b646e6c3a05018e132515c5eda98ca13d50d

(cherry picked from commit 26ef6a9c2da06b7de4116c483f9197fd4cf2a4cb)
---
 ...ap-buffer-underread-in-set_buf_break.patch | 123 ++++++++++++++++++
 .../recipes-extended/indent/indent_2.2.12.bb  |   1 +
 2 files changed, 124 insertions(+)
 create mode 100644 meta-oe/recipes-extended/indent/indent/0001-Fix-a-heap-buffer-underread-in-set_buf_break.patch
meta-oe/recipes-extended/indent/indent/0001-Fix-a-heap-buffer-underread-in-set_buf_break.patch new file +123 -0
new file mode 100644
index 0000000000..9938b6ebed
@@ -0,0 +1,123 @@
+From ec3ce4dce7f0bc6f15e8a29eeb3776359e0750fb Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <[email protected]>
+Date: Fri, 22 Nov 2024 17:27:21 +0800
+Subject: [PATCH] Fix a heap buffer underread in set_buf_break()
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+If an opening parenthesis follows a comment with a text, a read from
+an invalid address happens in set_buf_break():
+
+    $ printf '/*a*/()' | valgrind -- ./src/indent - -o /dev/null
+    ==28887== Memcheck, a memory error detector
+    ==28887== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+    ==28887== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
+    ==28887== Command: ./src/indent - -o /dev/null
+    ==28887==
+    ==28887== Invalid read of size 2
+    ==28887==    at 0x409989: set_buf_break (output.c:319)
+    ==28887==    by 0x401FE7: indent_main_loop (indent.c:640)
+    ==28887==    by 0x4022A7: indent (indent.c:759)
+    ==28887==    by 0x40294E: indent_single_file (indent.c:1004)
+    ==28887==    by 0x402A1C: indent_all (indent.c:1042)
+    ==28887==    by 0x402BD0: main (indent.c:1123)
+    ==28887==  Address 0x4a5facc is 4 bytes before a block of size 16 alloc'd
+    ==28887==    at 0x4849E60: calloc (vg_replace_malloc.c:1595)
+    ==28887==    by 0x408B61: xmalloc (globs.c:42)
+    ==28887==    by 0x40765E: init_parser (parse.c:73)
+    ==28887==    by 0x402B1F: main (indent.c:1101)
+
+It happens when checking an indentation level of the outer scope by indexing
+parser_state_tos->paren_indents[]:
+
+    level = parser_state_tos->p_l_follow;
+    [...]
+    /* Did we just parse a bracket that will be put on the next line
+     * by this line break? */
+    if ((*token == '(') || (*token == '['))
+        --level;    /* then don't take it into account */
+    [...]
+    if (level == 0) {
+    } else {
+→       if (parser_state_tos->paren_indents[level - 1] < 0) {...}
+    }
+
+The cause is a special case for moving opening parentheses and
+brackets to a next line. If parser_state_tos->p_l_follow is zero
+(like in the reproducer), the index evaluates to -2 and goes out of
+range of the paren_indents array.
+
+This patch simply prevents from decreasing the index under zero when
+formating the code. Maybe it leaves some piece of code unformated, but
+it's safe.
+
+I checked all places where p_l_follow is set (it is only in
+handletoken.c) and they corretly prevent from decrasing it under
+zero. That keeps set_buf_break() in output.c as the culprit.
+
+<https://lists.gnu.org/archive/html/bug-indent/2024-01/msg00000.html>
+
+Signed-off-by: Petr Písař <[email protected]>
+
+CVE: CVE-2024-0911
+Upstream-Status: Backport [feb2b646e6c3a05018e132515c5eda98ca13d50d
+Signed-off-by: Hongxu Jia <[email protected]>
+---
+ regression/TEST                                     | 2 +-
+ regression/input/comment-parent-heap-underread.c    | 3 +++
+ regression/standard/comment-parent-heap-underread.c | 5 +++++
+ src/output.c                                        | 2 +-
+ 4 files changed, 10 insertions(+), 2 deletions(-)
+ create mode 100644 regression/input/comment-parent-heap-underread.c
+ create mode 100644 regression/standard/comment-parent-heap-underread.c
+
+diff --git a/regression/TEST b/regression/TEST
+index a76c112..0888a18 100755
+--- a/regression/TEST
++++ b/regression/TEST
+@@ -38,7 +38,7 @@ BUGS="case-label.c one-line-1.c one-line-2.c one-line-3.c \
+         macro.c enum.c elif.c nested.c wrapped-string.c minus_predecrement.c \
+         bug-gnu-33364.c float-constant-suffix.c block-comments.c \
+         no-forced-nl-in-block-init.c hexadecimal_float.c \
+-        comment-heap-overread.c"
++        comment-heap-overread.c comment-parent-heap-underread.c"
+ 
+ INDENTSRC="args.c backup.h backup.c dirent_def.h globs.c indent.h \
+         indent.c indent_globs.h io.c lexi.c memcpy.c parse.c pr_comment.c \
+diff --git a/regression/input/comment-parent-heap-underread.c b/regression/input/comment-parent-heap-underread.c
+new file mode 100644
+index 0000000..68e13cf
+--- /dev/null
++++ b/regression/input/comment-parent-heap-underread.c
+@@ -0,0 +1,3 @@
++void foo(void) {
++/*a*/(1);
++}
+diff --git a/regression/standard/comment-parent-heap-underread.c b/regression/standard/comment-parent-heap-underread.c
+new file mode 100644
+index 0000000..9a1c6e3
+--- /dev/null
++++ b/regression/standard/comment-parent-heap-underread.c
+@@ -0,0 +1,5 @@
++void
++foo (void)
++{
++/*a*/ (1);
++}
+diff --git a/src/output.c b/src/output.c
+index 5b92167..b8a4961 100644
+--- a/src/output.c
++++ b/src/output.c
+@@ -290,7 +290,7 @@ void set_buf_break (
+     /* Did we just parse a bracket that will be put on the next line
+      * by this line break? */
+ 
+-    if ((*token == '(') || (*token == '['))
++    if (level > 0 && ((*token == '(') || (*token == '[')))
+     {
+         --level;                        /* then don't take it into account */
+     }
+-- 
+2.34.1
+
meta-oe/recipes-extended/indent/indent_2.2.12.bb +1 -0
index 2326f47b44..000abe4447 100644
@@ -19,6 +19,7 @@ SRC_URI = "${GNU_MIRROR}/${BPN}/${BP}.tar.gz \
            file://0001-Remove-dead-paren_level-code.patch \
            file://CVE-2023-40305_0001.patch \
            file://CVE-2023-40305_0002.patch \
+           file://0001-Fix-a-heap-buffer-underread-in-set_buf_break.patch \
            "
 SRC_URI[sha256sum] = "e77d68c0211515459b8812118d606812e300097cfac0b4e9fb3472664263bb8b"
 
#2 lore raw

PATCH 3/3 indent: upgrade 2.2.12 -> 2.2.13

In reply to Gyorgy Sarvari

Drop 0001-Fix-builds-with-recent-gettext.patch - it built fine for me without it.

Building requires full makeinfo, not only a lite version, so switched the texinfo class to texinfo-replacement-native dependency.

Changelog:
- Fix buffer overflows and use after free bugs
- Recognize binary integer literals
- New and updated translations, thanks to our translators:
- Updated translations:
Catalan, Croatian, French, Galician, German, Greek, Hungarian, Indonesian, Italian, Romanian, Serbian, Spanish, Turkish, Ukrainian
- New translation: Portuguese

---
 ...ap-buffer-underread-in-set_buf_break.patch |  4 +--
 .../0001-Fix-builds-with-recent-gettext.patch | 32 -------------------
 ...01-Makefile.am-remove-regression-dir.patch | 11 +++----
 .../0001-Remove-dead-paren_level-code.patch   | 27 +++++++---------
 .../indent/indent/CVE-2023-40305_0001.patch   |  8 ++---
 .../{indent_2.2.12.bb => indent_2.2.13.bb}    |  7 ++--
 6 files changed, 25 insertions(+), 64 deletions(-)
 delete mode 100644 meta-oe/recipes-extended/indent/indent/0001-Fix-builds-with-recent-gettext.patch
 rename meta-oe/recipes-extended/indent/{indent_2.2.12.bb => indent_2.2.13.bb} (83%)
meta-oe/recipes-extended/indent/indent/0001-Fix-a-heap-buffer-underread-in-set_buf_break.patch +2 -2
index 9938b6ebed..49adf84aa7 100644
@@ -76,10 +76,10 @@ diff --git a/regression/TEST b/regression/TEST
 index a76c112..0888a18 100755
 --- a/regression/TEST
 +++ b/regression/TEST
-@@ -38,7 +38,7 @@ BUGS="case-label.c one-line-1.c one-line-2.c one-line-3.c \
+@@ -40,7 +40,7 @@
          macro.c enum.c elif.c nested.c wrapped-string.c minus_predecrement.c \
          bug-gnu-33364.c float-constant-suffix.c block-comments.c \
-         no-forced-nl-in-block-init.c hexadecimal_float.c \
+         no-forced-nl-in-block-init.c hexadecimal_float.c binary-constant.c \
 -        comment-heap-overread.c"
 +        comment-heap-overread.c comment-parent-heap-underread.c"
  
meta-oe/recipes-extended/indent/indent/0001-Fix-builds-with-recent-gettext.patch deleted +0 -32
deleted file mode 100644
index e9dadace02..0000000000
@@ -1,32 +0,0 @@
-From 3349812de0598ca7722e0b7c7b7e5d48bd79bea9 Mon Sep 17 00:00:00 2001
-From: Alexander Kanavin <[email protected]>
-Date: Fri, 20 Dec 2019 14:01:18 +0100
-Subject: [PATCH] Fix builds with recent gettext
-
-Upstream-Status: Pending
-Signed-off-by: Alexander Kanavin <[email protected]>
----
- Makefile.am | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
---- a/Makefile.am
-+++ b/Makefile.am
-@@ -1,7 +1,7 @@
- ## Process this file with automake to produce Makefile.in
- AUTOMAKE_OPTIONS = no-texinfo.tex
- 
--SUBDIRS = intl src doc po man
-+SUBDIRS = src po man
- 
- BUILT_SOURCES = 
- 
---- a/configure.ac
-+++ b/configure.ac
-@@ -58,7 +58,6 @@ fi
- AC_HEADER_DIRENT
- 
- AC_OUTPUT([ 
--   intl/Makefile
-    po/Makefile.in
-    Makefile
-    src/Makefile
meta-oe/recipes-extended/indent/indent/0001-Makefile.am-remove-regression-dir.patch +4 -7
index 357d77d835..e4e0ac590c 100644
@@ -47,13 +47,13 @@ index ba37a42..548fea7 100644
  ## Process this file with automake to produce Makefile.in
  AUTOMAKE_OPTIONS = no-texinfo.tex
  
--SUBDIRS = intl src doc po man regression
-+SUBDIRS = intl src doc po man
+-SUBDIRS = src doc po man regression
++SUBDIRS = src doc po man
  
  BUILT_SOURCES = 
  
-@@ -13,8 +13,7 @@ EXTRA_DIST = 	README.md \
- 		aclocal/UTIMBUF.m4 \
+@@ -13,8 +13,7 @@
+ 		m4/UTIMBUF.m4 \
  		miscel/Makefile.mingw32 \
  		miscel/README.vc++ \
 -		bootstrap \
@@ -62,6 +62,3 @@ index ba37a42..548fea7 100644
  
  DISTCLEANFILES=config/config.cache config/config.log config.h
  
--- 
-2.17.1
-
meta-oe/recipes-extended/indent/indent/0001-Remove-dead-paren_level-code.patch +12 -15
index 5a474cf0fc..3c7856e571 100644
@@ -18,14 +18,10 @@ diff --git a/src/output.c b/src/output.c
 index ee01bcc..5b92167 100644
 --- a/src/output.c
 +++ b/src/output.c
-@@ -798,37 +798,6 @@ static int dump_line_label(void)
-    return cur_col;
- }
+@@ -802,37 +802,6 @@
+  *
+  */
  
--/**
-- *
-- */
--
 -static int count_parens(
 -    const char * string)
 -{
@@ -53,10 +49,14 @@ index ee01bcc..5b92167 100644
 -    return paren_level;
 -}
 -
- /**
-  *
-  */
-@@ -840,8 +809,6 @@ static void dump_line_code(
+-/**
+- *
+- */
+-
+ static void dump_line_code(
+     int     * pcur_col,
+     int     * pnot_truncated,
+@@ -840,8 +809,6 @@
      BOOLEAN * pbreak_line,
      int       target_col_break)
  {
@@ -65,7 +65,7 @@ index ee01bcc..5b92167 100644
     if (s_code != e_code)
     {                       /* print code section, if any */
        int i;
-@@ -928,8 +895,6 @@ static void dump_line_code(
+@@ -928,8 +895,6 @@
  
           *pcur_col = count_columns (*pcur_col, s_code, NULL_CHAR);
  
@@ -74,6 +74,3 @@ index ee01bcc..5b92167 100644
           s_code[buf_break->offset] = c;
  
           *pnot_truncated = 0;
--- 
-2.31.1
-
meta-oe/recipes-extended/indent/indent/CVE-2023-40305_0001.patch +4 -4
index 367202e3c5..ae48271732 100644
@@ -74,14 +74,14 @@ diff --git a/regression/TEST b/regression/TEST
 index 56f41d9..a7a6747 100755
 --- a/regression/TEST
 +++ b/regression/TEST
-@@ -37,7 +37,8 @@ BUGS="case-label.c one-line-1.c one-line-2.c one-line-3.c \
+@@ -39,7 +39,8 @@
          one-line-4.c struct-decl.c sizeof-in-while.c line-break-comment.c \
          macro.c enum.c elif.c nested.c wrapped-string.c minus_predecrement.c \
          bug-gnu-33364.c float-constant-suffix.c block-comments.c \
--        no-forced-nl-in-block-init.c hexadecimal_float.c"
-+        no-forced-nl-in-block-init.c hexadecimal_float.c \
+-        no-forced-nl-in-block-init.c hexadecimal_float.c binary-constant.c"
++        no-forced-nl-in-block-init.c hexadecimal_float.c binary-constant.c \
 +        comment-heap-overread.c"
-
+ 
  INDENTSRC="args.c backup.h backup.c dirent_def.h globs.c indent.h \
          indent.c indent_globs.h io.c lexi.c memcpy.c parse.c pr_comment.c \
 diff --git a/regression/input/comment-heap-overread.c b/regression/input/comment-heap-overread.c
meta-oe/recipes-extended/indent/indent_2.2.13.bb renamed from meta-oe/recipes-extended/indent/indent_2.2.12.bb +3 -4
similarity index 83%
rename from meta-oe/recipes-extended/indent/indent_2.2.12.bb
rename to meta-oe/recipes-extended/indent/indent_2.2.13.bb
index 000abe4447..f9d5025a65 100644
@@ -10,20 +10,19 @@ you want a program to format your code."
 LICENSE = "GPL-3.0-only"
 LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
 
-DEPENDS = "virtual/gettext"
+DEPENDS = "virtual/gettext texinfo-replacement-native"
 
 SRC_URI = "${GNU_MIRROR}/${BPN}/${BP}.tar.gz \
            file://0001-src-indent.c-correct-the-check-for-locale.h.patch \
            file://0001-Makefile.am-remove-regression-dir.patch \
-           file://0001-Fix-builds-with-recent-gettext.patch \
            file://0001-Remove-dead-paren_level-code.patch \
            file://CVE-2023-40305_0001.patch \
            file://CVE-2023-40305_0002.patch \
            file://0001-Fix-a-heap-buffer-underread-in-set_buf_break.patch \
            "
-SRC_URI[sha256sum] = "e77d68c0211515459b8812118d606812e300097cfac0b4e9fb3472664263bb8b"
+SRC_URI[sha256sum] = "9e64634fc4ce6797b204bcb8897ce14fdd0ab48ca57696f78767c59cae578095"
 
-inherit autotools gettext texinfo
+inherit autotools gettext
 
 CFLAGS:append:class-native = " -Wno-error=unused-value"