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: prevent buffer overflow when reading ...



details:   https://anonhg.NetBSD.org/src/rev/9f5230050f90
branches:  trunk
changeset: 1024007:9f5230050f90
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 07 16:45:38 2021 +0000

description:
indent: prevent buffer overflow when reading profile

diffstat:

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

diffs (29 lines):

diff -r f0b998a02338 -r 9f5230050f90 usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Thu Oct 07 13:04:18 2021 +0000
+++ b/usr.bin/indent/args.c     Thu Oct 07 16:45:38 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: args.c,v 1.43 2021/10/03 19:09:59 rillig Exp $ */
+/*     $NetBSD: args.c,v 1.44 2021/10/07 16:45:38 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.43 2021/10/03 19:09:59 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.44 2021/10/07 16:45:38 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -164,6 +164,10 @@
            } else if (isspace((unsigned char)ch)) {
                if (p > buf && comment_index == 0)
                    break;
+           } else if ((size_t)(p - buf) >= nitems(buf) - 5) {
+               diag(1, "buffer overflow in %s, starting with '%.10s'",
+                    option_source, buf);
+               exit(1);
            } else {
                *p++ = (char)ch;
            }



Home | Main Index | Thread Index | Old Index