bug in commit 20f6b54385d2462d858419f7c67509cb3d22d155

Denys Vlasenko vda.linux at googlemail.com
Mon Mar 26 11:21:47 UTC 2012


Hi Dmitry,

 for file in "$logfile".*; do
        [ -f "$file" ] || continue
-       suffix=${file:1+$pfxlen}
-       [ "$suffix" -gt 0 ] 2> /dev/null || {
-               echo "Skipped file '$file' (bad suffix)" >&2
+       suffix=${file#$logfile.}

suffix=${file#$logfile.} is not a good way to strip $logfile prefix:
${var#pattern} operation interprets <pattern>, indeed, as glob pattern.
Even if it is inside a variable.

Try this:

logfile="????"
file=FILE.123
suffix=${file#$logfile.}
echo "$suffix"

It will print "123" - thus, it "removed the prefix and the dot",
but it is wrong: string "FILE.123" hasn't got the "????" prefix!

The bug is not very dangerous (who in their right mind would use
? and * in actual filenames?) but nevertheless, it's a bug.
I think we'd better use suffix=${file:1+$pfxlen}.

-- 
vda




More information about the Strace-devel mailing list