Module Name: src Committed By: rillig Date: Sun Nov 7 13:38:32 UTC 2021
Modified Files: src/usr.bin/indent: pr_comment.c Log Message: indent: remove code that accessed out-of-bounds data from buffer Saving and restoring the exact buffer position had been necessary before NetBSD pr_comment.c 1.114. The code accessed the buffer data out of the bounds of [com.s, com.e), which was rather surprising. More specifically, it accessed com.e[-1] in a case where com.e == com.s, relying on com.e[-1] being ' ' in most cases and '*' in the case where the comment delimiter was written to a separate output line. Make the code easier understandable by only ever accessing the buffer data in the bounds [buf.s, buf.e). No functional change. To generate a diff of this commit: cvs rdiff -u -r1.114 -r1.115 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.114 src/usr.bin/indent/pr_comment.c:1.115 --- src/usr.bin/indent/pr_comment.c:1.114 Sun Nov 7 13:30:15 2021 +++ src/usr.bin/indent/pr_comment.c Sun Nov 7 13:38:32 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.114 2021/11/07 13:30:15 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.115 2021/11/07 13:38:32 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.114 2021/11/07 13:30:15 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.115 2021/11/07 13:38:32 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -181,14 +181,12 @@ analyze_comment(bool *p_may_wrap, bool * break_delim = false; if (break_delim) { - char *t = com.e; com.e = com.s + 2; *com.e = '\0'; if (opt.blanklines_before_block_comments && ps.prev_token != lsym_lbrace) blank_line_before = true; dump_line(); - com.e = com.s = t; com_add_delim(); }