Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/indent indent: demonstrate controlled buffer o...



details:   https://anonhg.NetBSD.org/src/rev/1a09cf8944a8
branches:  trunk
changeset: 1024879:1a09cf8944a8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 07 19:04:46 2021 +0000

description:
indent: demonstrate controlled buffer overflow in C99 comment

diffstat:

 tests/usr.bin/indent/t_misc.sh |  20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diffs (40 lines):

diff -r 7e46ba95be23 -r 1a09cf8944a8 tests/usr.bin/indent/t_misc.sh
--- a/tests/usr.bin/indent/t_misc.sh    Sun Nov 07 18:49:02 2021 +0000
+++ b/tests/usr.bin/indent/t_misc.sh    Sun Nov 07 19:04:46 2021 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.13 2021/11/07 15:01:50 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.14 2021/11/07 19:04:46 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -364,6 +364,23 @@
            "$indent" -Pnonexistent.pro -Perror.pro -Plast.pro code.c -st
 }
 
+atf_test_case 'if_expr_c99_comment'
+if_expr_c99_comment_body()
+{
+       cat <<-\EOF >> code.c
+               void function(void) {
+                       if (expr) // C99 comment
+                               stmt();
+               }
+       EOF
+       cat <<-\EOF >> code.err
+               error: code.c:2: Internal buffer overflow - Move big comment from right after if, while, or whatever
+       EOF
+
+       atf_check -s 'exit:1' -o 'ignore' -e 'file:code.err' \
+           "$indent" code.c -st
+}
+
 atf_init_test_cases()
 {
        atf_add_test_case 'in_place'
@@ -377,4 +394,5 @@
        atf_add_test_case 'line_no_counting'
        atf_add_test_case 'default_backup_extension'
        atf_add_test_case 'several_profiles'
+       atf_add_test_case 'if_expr_c99_comment'
 }



Home | Main Index | Thread Index | Old Index