Module Name:    src
Committed By:   rillig
Date:           Sat Oct 30 18:23:17 UTC 2021

Modified Files:
        src/usr.bin/indent: pr_comment.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/indent/pr_comment.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.91 src/usr.bin/indent/pr_comment.c:1.92
--- src/usr.bin/indent/pr_comment.c:1.91	Sat Oct 30 16:57:18 2021
+++ src/usr.bin/indent/pr_comment.c	Sat Oct 30 18:23:17 2021
@@ -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 @@ static char sccsid[] = "@(#)pr_comment.c
 
 #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 @@ process_comment(void)
 	/*
 	 * 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 {

Reply via email to