Permalink
Browse files

workaround for unknown '--' argument while calling 'expr' from BusyBox

- a patch will be suggested to the BusyBox mailing list to skip the
  'end of options' marker according to POSIX specifications, if it's
  the first argument to 'expr'

- this problem may be solved with additional parentheses around the
  regexp match, too - this way the string with unknown contents as
  arg1 can't be misinterpreted as an option
  • Loading branch information...
PeterPawn committed Sep 19, 2017
1 parent 46ae03d commit 67abdeebd64ebce229c9dfcca32554c30c16b9e4
@@ -35,7 +35,7 @@ yf_base32_decode()
rc=1 # preset, if no newline is present on STDIN, our 'read' will signal instant EOF
while read line; do
rc=0
! [ -z "$(expr -- "$line" : "\([^A-Z1-6\r]\)")" ] && return 1
! [ -z "$(expr \( "$line" : "\([^A-Z1-6\r]\)" \) )" ] && return 1
line=$(printf "%s" $line | sed -e "s|\r||g")
[ $(( ${#line} % 8 )) -gt 0 ] && return 1
i=0
@@ -36,7 +36,7 @@ yf_base64_decode()
rc=$?
else
while read line; do
! [ -z "$(expr -- "$line" : "\([^A-Za-z0-9+/\r=]\)")" ] && return 1
! [ -z "$(expr \( "$line" : "\([^A-Za-z0-9+/\r=]\)" \) )" ] && return 1
line=$(printf "%s" $line | sed -e "s|\r||g")
[ $(( ${#line} % 4 )) -gt 0 ] && return 1
i=0
@@ -47,8 +47,8 @@ yf_random_string()
else
v=0
while [ ${#val} -gt 0 ]; do
v=$(( ( v << 3 ) + $(expr -- "$val" : "\([0-9]\).*") ))
val="$(expr -- "$val" : "[0-9]\([0-9]*\)")"
v=$(( ( v << 3 ) + $(expr \( "$val" : "\([0-9]\).*" \) ) ))
val="$(expr \( "$val" : "[0-9]\([0-9]*\)" \) )"
done
yf_random_string_read_octals_print "$v" "$len"
len=$(( len - 2 ))
@@ -38,6 +38,6 @@ yf_substring()
[ -z $len ] || [ $len -gt $(( ${#in} - start )) ] && len=$(( ${#in} - start ))
len="\{$len\}"
[ $start -gt 0 ] && mask=".\{$start\}\(.$len\).*" || mask="\(.$len\).*"
expr -- "$in" : "$mask"
expr \( "$in" : "$mask" \)
return 0
)

0 comments on commit 67abdee

Please sign in to comment.