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 bounds check for sc_buf



details:   https://anonhg.NetBSD.org/src/rev/f68bee29a053
branches:  trunk
changeset: 990586:f68bee29a053
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 30 18:23:17 2021 +0000

description:
indent: fix bounds check for sc_buf

Some years ago, save_com was an array of characters, used as temporary
storage. When sc_buf was added, this code was forgotten. The bounds
check must be on the array itself, not on an iterator that points
somewhere in that array.

diffstat:

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

diffs (31 lines):

diff -r ff37d4bd8100 -r f68bee29a053 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sat Oct 30 17:55:44 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Sat Oct 30 18:23:17 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.91 2021/10/30 16:57:18 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.92 2021/10/30 18:23:17 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.91 2021/10/30 16:57:18 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.92 2021/10/30 18:23:17 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -189,11 +189,8 @@
        /*
         * XXX: ordered comparison between pointers from different objects
         * invokes undefined behavior (C99 6.5.8).
-        *
-        * XXX: It's easier to understand if inp.s is used instead of inp.buf,
-        * since inp.buf is only intended to be used for allocation purposes.
         */
-       start = inp.s >= save_com && inp.s < save_com + sc_size ?
+       start = inp.s >= sc_buf && inp.s < sc_buf + sc_size ?
            sc_buf : inp.buf;
        ps.n_comment_delta = -indentation_after_range(0, start, inp.s - 2);
     } else {



Home | Main Index | Thread Index | Old Index