diff --git a/sh/oxo b/sh/oxo index 7f9c7be..90b40d9 100755 --- a/sh/oxo +++ b/sh/oxo @@ -62,7 +62,21 @@ oxo() { ### @- : $((fails+=1)) printf "$bad" "oxo: skipping empty file: $f" >&2 else - local kib="$(du -k "$f" | cut -f1)" + local g="$f" + + # restrict the filepath to simple ascii characters that curl likes. + if [ -n "$(printf '%s' "$f" | tr -d \''0-9A-Za-z !#$%&()*+,./;=@[]^_`{}~-')" ]; then + # copy the user's file to a temporary path and use that instead. + g=/tmp/oxo + #printf "$warn" "oxo: special characters found: $f" >&2 + if ! cp -p -- "$f" "$g"; then + : $((fails+=1)) + printf "$bad" "oxo: failed to copy file: $f" >&2 + continue + fi + fi + + local kib="$(du -k -- "$f" | cut -f1)" if [ "$kib" -gt 524288 ]; then : $((fails+=1)) @@ -78,17 +92,13 @@ oxo() { ### @- local d=$(( b*c/8192+3*kib/16+1-32768 )) local r=$(( (d*-335+16384)/32768+30 )) - if ! cp -p "$f" /tmp/0x0; then - : $((fails+=1)) - printf "$bad" "oxo: failed to copy file: $f" >&2 - elif ! curl -F'file=@/tmp/0x0' https://0x0.st; then + if ! curl -F"file=@\"$g\"" https://0x0.st; then : $((fails+=1)) printf "$bad" "oxo: failed to upload file: $f" >&2 else : $((succs+=1)) printf "$look" "oxo: expires in $r days: $f" >&2 fi - #rm -f /tmp/0x0 fi done @@ -103,6 +113,8 @@ oxo() { ### @- printf "$err" "oxo: failed to upload $fails file$s" >&2 fi + [ ! -e /tmp/oxo ] || rm /tmp/oxo + return $fails }