Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: fix out-of-bounds read when reducing ...



details:   https://anonhg.NetBSD.org/src/rev/24390bdecf39
branches:  trunk
changeset: 376378:24390bdecf39
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jun 14 17:52:45 2023 +0000

description:
indent: fix out-of-bounds read when reducing a statement

Since parse.c 1.73 from today. The parser symbol psym_stmt_list that was
removed in that commit acted as a stop symbol, so that psyms_reduce_stmt
would save a memory access.

diffstat:

 usr.bin/indent/parse.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 7eeefe5bdb56 -r 24390bdecf39 usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Wed Jun 14 17:07:32 2023 +0000
+++ b/usr.bin/indent/parse.c    Wed Jun 14 17:52:45 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.74 2023/06/14 16:14:30 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.75 2023/06/14 17:52:45 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: parse.c,v 1.74 2023/06/14 16:14:30 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.75 2023/06/14 17:52:45 rillig Exp $");
 
 #include <err.h>
 
@@ -116,7 +116,7 @@ static void
 psyms_reduce(struct psym_stack *psyms)
 {
 again:
-       if (psyms->sym[psyms->len - 1] == psym_stmt
+       if (psyms->len >= 2 && psyms->sym[psyms->len - 1] == psym_stmt
            && psyms_reduce_stmt(psyms))
                goto again;
        if (psyms->sym[psyms->len - 1] == psym_while_expr &&



Home | Main Index | Thread Index | Old Index