Skip to content

Commit

Permalink
Insufficient validation in @define #85
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Dec 22, 2021
1 parent 23ec4df commit bad72d9
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 51 deletions.
8 changes: 4 additions & 4 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function handleDefineLine(line, kv) {
DefinesCode = addL(DefinesCode, line "\nexport " kv[0])
}
function checkValidDefineSyntax(line) {
if (line ~ /[ \t]*[A-Za-z_][A-Za-z0-9_]*=((([^ ;'"]|(\\ ))([^ ;]|(\\ ))*)|('[^']*')|("((\\\\)|(\\")|[^"])*")|(\$'((\\\\)|(\\')|[^'])*'))+[ \t]*(#.*)?$/)
if (line ~ /^[ \t]*[A-Za-z_][A-Za-z0-9_]*=(([A-Za-z0-9_]|(\\.))+|('[^']*')|("((\\\\)|(\\")|[^"])*")|(\$'((\\\\)|(\\')|[^'])*'))+[ \t]*(#.*)?$/)
return 1
addError("Invalid define declaration")
return 0
Expand Down Expand Up @@ -514,9 +514,9 @@ function shellExec(script, comment, res) {
} else
script = Shell " -e -c " quoteArg(script)

# This is hard to unit-test properly.
# The issue with Ctrl-C only happens with Gawk 4.1.3.
# The manual test exists via `expect -f tests/manual_ctrl_c.expect.txt`
# This is hard to unit-test properly.
# The issue with Ctrl-C only happens with Gawk 4.1.3.
# The manual test exists via `expect -f tests/manual_ctrl_c.expect.txt`
script = "trap 'exit 7' INT;" script

#print script
Expand Down
2 changes: 1 addition & 1 deletion tests/10_define.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


@define A=aaa
@define B=${A}bbb
@define B="${A}bbb"
@define Commented=value # just a comment

@goal testA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
@define B='bbb bbb'
@define B1='bbb # bbb'
@define B2='bbb ; bbb'
@define B3='bbb ; bbb';
@define B4='bbb ; bbb' ;
@define C=$'cc\'c cc\'c'
@define C1='cc'\''c cc'\''c'
@define D=a\ b\ \ c
@define D1=a\b\c\d
@define D2=a\'\c\"
@define E="eee eee"
@define F="eee \\ \" eee"

Expand All @@ -18,8 +18,6 @@
@define AC2=aaa# # comment
@define BC1='bbb bbb' # comment
@define BC2='bbb bbb'# # comment
@define BC3='bbb bbb'; # comment
@define BC4='bbb ; bbb' ; # comment
@define CC1=$'cc\'c cc\'c' #
@define DC1=a\ b\ c #
@define EC1="eee" # comment
Expand All @@ -28,7 +26,7 @@
@define LC1="$A$B$C$D$E" # other comment

@goal default
for x in A B B1 B2 B3 B4 C C1 D E F K L AC1 AC2 BC1 BC2 BC3 BC4 CC1 DC1 EC1 KC1 LC1
for x in A B B1 B2 C C1 D D1 D2 E F K L AC1 AC2 BC1 BC2 CC1 DC1 EC1 KC1 LC1
do
printf '%-3s=%s\n' "$x" "${!x}"
done
Expand Down
83 changes: 83 additions & 0 deletions tests/16_define_validation.tush
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

$ cd "$MYDIR"; ./$MAKESURE -f tests/16_define_validation.sh
| goal 'default' ...
| A =aaa
| B =bbb bbb
| B1 =bbb # bbb
| B2 =bbb ; bbb
| C =cc'c cc'c
| C1 =cc'c cc'c
| D =a b c
| D1 =abcd
| D2 =a'c"
| E =eee eee
| F =eee \ " eee
| K =aaabbbcc'ca b ceee
| L =aaabbb bbb cc'c cc'ca b c eee eee
| AC1=aaa
| AC2=aaa#
| BC1=bbb bbb
| BC2=bbb bbb#
| CC1=cc'c cc'c
| DC1=a b c
| EC1=eee
| KC1=aaabbbcc'ca b ceee
| LC1=aaabbb bbbcc'c cc'ca b ceee eee

$ cd "$MYDIR"; ./$MAKESURE -f tests/16_define_validation_error.sh
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:2: @define echo
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:3: @define echo;
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:4: @define echo;echo
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:5: @define echo ; echo
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:6: @define echo 'Hello'
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:7: @define echo 'Hello';
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:8: @define A=aaa echo 'Hello'
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:9: @define B=aaa\ aaa echo 'Hello'
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:10: @define C='aaa aaa' echo 'Hello'
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:12: @define echo # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:13: @define echo 'Hello' # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:14: @define echo 'Hello'; # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:15: @define echo 'Hello' ;# comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:16: @define A=aaa echo 'Hello' # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:17: @define B=aaa\ aaa echo 'Hello'# comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:18: @define C='aaa aaa' echo 'Hello' # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:19: @define C='aaa aaa' echo 'Hello' ; # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:22: @define B3='bbb ; bbb';
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:23: @define B4='bbb ; bbb' ;
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:24: @define BC3='bbb bbb'; # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:25: @define BC4='bbb ; bbb' ; # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:28: @define IL1=a||b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:29: @define IL2=a&b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:30: @define IL3=a&&b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:31: @define IL4=a!b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:32: @define IL5=a-b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:33: @define IL5=a+b
? 1

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
@define C='aaa aaa' echo 'Hello' # comment
@define C='aaa aaa' echo 'Hello' ; # comment

# Let's disallow ';' for simplicity and unification
@define B3='bbb ; bbb';
@define B4='bbb ; bbb' ;
@define BC3='bbb bbb'; # comment
@define BC4='bbb ; bbb' ; # comment

# Illegal chars. This is more restrictive than shell but simpler to parse
@define IL1=a||b
@define IL2=a&b
@define IL3=a&&b
@define IL4=a!b
@define IL5=a-b
@define IL5=a+b

@goal default
echo 'Should not show'

6 changes: 0 additions & 6 deletions tests/16_prelude_fail.sh

This file was deleted.

7 changes: 0 additions & 7 deletions tests/16_prelude_fail.tush

This file was deleted.

4 changes: 2 additions & 2 deletions tests/22_nat_order.tush
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/22_nat_order.sh nat_order_test
| 13_doc.tush
| 14_private.tush
| 15_lib.tush
| 16_prelude_fail.tush
| 16_define_validation.tush
| 17_empty_prelude.tush
| 18_vars_priority.tush
| 19_optimize_goals.tush
Expand All @@ -40,7 +40,7 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/22_nat_order nat_order_test
| ../13_doc.tush
| ../14_private.tush
| ../15_lib.tush
| ../16_prelude_fail.tush
| ../16_define_validation.tush
| ../17_empty_prelude.tush
| ../18_vars_priority.tush
| ../19_optimize_goals.tush
Expand Down
26 changes: 0 additions & 26 deletions tests/24_define_validation.tush

This file was deleted.

0 comments on commit bad72d9

Please sign in to comment.