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: don't risk a buffer overflow in code_...



details:   https://anonhg.NetBSD.org/src/rev/aa311c9d4404
branches:  trunk
changeset: 990560:aa311c9d4404
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 30 11:10:36 2021 +0000

description:
indent: don't risk a buffer overflow in code_add_decl_indent

The buffers have a safety margin of 5 characters, so the bounds check is
not strictly necessary. It makes the code more uniform though.

No functional change.

diffstat:

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

diffs (27 lines):

diff -r 822e48e718cb -r aa311c9d4404 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Oct 30 11:05:26 2021 +0000
+++ b/usr.bin/indent/indent.c   Sat Oct 30 11:10:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.184 2021/10/30 11:05:26 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.185 2021/10/30 11:10:36 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.184 2021/10/30 11:05:26 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.185 2021/10/30 11:10:36 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -616,7 +616,7 @@
        buf_add_char(&code, ' ');
 
     if (code.e == orig_code_e && ps.want_blank) {
-       *code.e++ = ' ';
+       buf_add_char(&code, ' ');
        ps.want_blank = false;
     }
 }



Home | Main Index | Thread Index | Old Index