[Top][All Lists]

[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:

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" || {
        case $? in
           exit 1

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...

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

Attachment: tbug
Description: Text document

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]