Module Name: src Committed By: rillig Date: Thu Oct 7 16:45:38 UTC 2021
Modified Files: src/usr.bin/indent: args.c Log Message: indent: prevent buffer overflow when reading profile To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/args.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/args.c diff -u src/usr.bin/indent/args.c:1.43 src/usr.bin/indent/args.c:1.44 --- src/usr.bin/indent/args.c:1.43 Sun Oct 3 19:09:59 2021 +++ src/usr.bin/indent/args.c Thu Oct 7 16:45:38 2021 @@ -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 @@ static char sccsid[] = "@(#)args.c 8.1 ( #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 @@ load_profile(const char *fname) } 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; }