Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-10-02 10:55:20 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-10-02 13:35:06 -0400
commitc675207696ce8086d460ecbb2388caa76866bdbc (patch)
tree0bd7d59785a531bc300fe15df1fb198681ac957a /build-aux/csvm2csv
parentc741b4a84eebe397b89db08c6d4228fdc5afaa63 (diff)
downloadtame-c675207696ce8086d460ecbb2388caa76866bdbc.tar.gz
tame-c675207696ce8086d460ecbb2388caa76866bdbc.tar.bz2
tame-c675207696ce8086d460ecbb2388caa76866bdbc.zip
csvm2csv: Add some error checks
* build-aux/csvm2csv: Fail on invalid var definition. (expand_vars): Fail in invalid reference. (parseline): Fail on non-numeric range. * build-aux/test/test-csvm2csv (test-fail-unknown-var-ref, test-fail-non-numeric-range) (test-fail-invalid-var-dfn): New tests.
Diffstat (limited to 'build-aux/csvm2csv')
-rwxr-xr-xbuild-aux/csvm2csv25
1 files changed, 22 insertions, 3 deletions
diff --git a/build-aux/csvm2csv b/build-aux/csvm2csv
index 9b9dc19..addbe26 100755
--- a/build-aux/csvm2csv
+++ b/build-aux/csvm2csv
@@ -46,12 +46,20 @@
# Expand variable with its value, if any
-function expand_vars( s )
+function expand_vars( s, value )
{
# attempt to parse variable (may expand into a range)
if ( match( s, /^\$([a-zA-Z_-]+)$/, m ) )
{
- return vars[ m[1] ];
+ value = vars[ m[1] ];
+
+ if ( value == "" )
+ {
+ print "error: unknown variable reference: `$" m[1] "'" > "/dev/stderr"
+ exit 1
+ }
+
+ return value
}
return s
@@ -102,6 +110,12 @@ function parseline( i, m, j, me, orig )
j = expand_vars( m[1] )
me = expand_vars( m[2] )
+ if ( !match( j, /^[0-9]+$/ ) || !match( me, /^[0-9]+$/ ) )
+ {
+ print "error: invalid range: `" $i "'" > "/dev/stderr"
+ exit 1
+ }
+
do
{
$i = j
@@ -130,7 +144,12 @@ BEGIN {
# lines that begin with a colon are variable definitions
/^:/ {
- match( $0, /^:([a-zA-Z_-]+)=(.*?)$/, m )
+ if ( !match( $0, /^:([a-zA-Z_-]+)=(.*?)$/, m ) )
+ {
+ print "error: invalid variable definition: `" $0 "'" > "/dev/stderr"
+ exit 1
+ }
+
vars[ m[1] ] = m[2]
next
}