[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Interesting bug
From: |
David Hobach |
Subject: |
Interesting bug |
Date: |
Sat, 12 Feb 2022 12:23:31 +0100 |
Dear all,
I think I found a rather interesting bug:
```
#!/bin/bash
function badCode {
echo "bad code executed"
}
function testCode {
#pick some existing file, nonexisting works too though
echo "/etc/passwd"
}
function tfunc {
local foo=
foo="$(testCode)" || {echo "foo";}
cat "$foo" || {
badCode
case $? in
*)
exit 1
esac
}
}
echo "Finished."
```
(I also attached it.)
I guess 99% of programmers would either expect "Finished" to be printed or some syntax
error. In fact however the `badCode` function is executed. "Finished" is never executed.
This is a nice one to hide bad code...
Output:
```
cat: '': No such file or directory
bad code executed
```
Affected bash versions:
Debian 11: GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)
Fedora 32: GNU bash, version 5.0.17(1)-release (x86_64-redhat-linux-gnu)
(Probably more, these were the only two I tested.)
Happy bug hunting!
Best Regards
David
tbug
Description: Text document
smime.p7s
Description: S/MIME Cryptographic Signature
- Interesting bug,
David Hobach <=
- Re: Interesting bug, Martin Schulte, 2022/02/12
- Re: Interesting bug, David Hobach, 2022/02/12
- Re: Interesting bug, David Hobach, 2022/02/12
- Re: Interesting bug, Andreas Schwab, 2022/02/12
- Re: Interesting bug, Martin Schulte, 2022/02/12
- Re: Interesting bug, Ilkka Virta, 2022/02/12
- Re: Interesting bug, David Hobach, 2022/02/12
- Re: Interesting bug, Chet Ramey, 2022/02/13
- Re: Interesting bug, Chet Ramey, 2022/02/13
Re: Interesting bug, Léa Gris, 2022/02/12