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 memory access (sinc...



details:   https://anonhg.NetBSD.org/src/rev/306130ea1f12
branches:  trunk
changeset: 1026521:306130ea1f12
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 27 20:33:39 2021 +0000

description:
indent: fix out of bounds memory access (since 2021-11-25)

diffstat:

 tests/usr.bin/indent/fmt_decl.c |  15 ++++++++-------
 usr.bin/indent/lexi.c           |  18 ++++++++++++------
 2 files changed, 20 insertions(+), 13 deletions(-)

diffs (88 lines):

diff -r 8419d82193d7 -r 306130ea1f12 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Sat Nov 27 20:13:48 2021 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Sat Nov 27 20:33:39 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.31 2021/11/27 19:21:42 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.32 2021/11/27 20:33:39 rillig Exp $     */
 /* $FreeBSD: head/usr.bin/indent/tests/declarations.0 334478 2018-06-01 09:41:15Z pstef $ */
 
 /*
@@ -831,13 +831,13 @@
 
 
 /*
- * FIXME: Whether or not the function 'a' is a declaration or a definition
- * depends on the preceding struct, in particular the length of the 'pn'
- * line. This doesn't make sense at all and looks like an out-of-bounds memory
- * access.
+ * Since lexi.c 1.158 from 2021-11-25, whether the function 'a' was considered
+ * a declaration or a definition depended on the preceding struct, in
+ * particular the length of the 'pn' line. This didn't make sense at all and
+ * was due to an out-of-bounds memory access.
  *
- * Since lexi.c 1.158 from 2021-11-25.
  * Seen amongst others in args.c 1.72, function add_typedefs_from_file.
+ * Fixed in lexi.c 1.165 from 2021-11-27.
  */
 #indent input
 struct {
@@ -868,7 +868,8 @@
 };
 
 static void
-     a(char *fe){
+a(char *fe)
+{
 }
 
 struct {
diff -r 8419d82193d7 -r 306130ea1f12 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Sat Nov 27 20:13:48 2021 +0000
+++ b/usr.bin/indent/lexi.c     Sat Nov 27 20:33:39 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.164 2021/11/25 18:48:37 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.165 2021/11/27 20:33:39 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.164 2021/11/25 18:48:37 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.165 2021/11/27 20:33:39 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -450,21 +450,27 @@
     return strcmp(key, ((const struct keyword *)elem)->name);
 }
 
+/*
+ * Looking at a line starting with 'function_name(something)', guess whether
+ * this starts a function definition or a declaration.
+ */
 static bool
 probably_looking_at_definition(void)
 {
     int paren_level = 0;
     for (const char *p = inp_p(), *e = inp_line_end(); p < e; p++) {
-proceed:
        if (*p == '(')
            paren_level++;
        if (*p == ')' && --paren_level == 0) {
            p++;
            while (p < e && (ch_isspace(*p) || is_identifier_part(*p)))
                p++;
-           if (*p == '(')
-               goto proceed;
-           return !(*p == ';' || *p == ',');
+           if (p < e && (*p == ';' || *p == ','))
+               return false;
+           if (p < e && *p == '(')
+               paren_level++;
+           else
+               break;
        }
     }
 



Home | Main Index | Thread Index | Old Index