Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15280
| Path | csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Morgan McClure <mcclure.morgan@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | Incorrect passing of argc argv with multiple redirects |
| Date | Tue, 30 Jul 2019 10:08:54 -0700 |
| Lines | 44 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.281.1564507949.1985.bug-bash@gnu.org> (permalink) |
| References | <CANY-LFLTkqOyooA522KwuB1JEiaiUQ=N-5XEVWxueO14WLWWvQ@mail.gmail.com> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| X-Trace | usenet.stanford.edu 1564507949 11586 209.51.188.17 (30 Jul 2019 17:32:29 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=MPoZr7THX5g9w32lh8Piaom377JlU9lLdiKv2M24A4Y=; b=n2K1lDm/VD9y6SPHOSaYJ+AAuc3B6puvaUMjoxz80DTPJNEAl3DVc8La4WGHgLAb2X Nnr/HCmSwdt3Tz774fuaqZvVQeXBdecRJlxIvYsFgJECc37/f2rou8pJhrBZodbo8eWH ggCtIOMRlfxdTbKHMIy/z8Ve3Mw43o4JYtrUh9MeCjWARSEhNShyJILDmaMMyZC++gid ijxck/RAtnBAWDlV+12qbL4OqJLVgHKLxN0cTi+1DZ6wgW2sCKv9eBmF3xBp/ov9THfx 1xLy4rWIjGaQFV0iG3frkETH34XkfaWFi+lcqg6hk9eKqylUrLI6KRSeQV65Psq0GyRU 1W1w== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=MPoZr7THX5g9w32lh8Piaom377JlU9lLdiKv2M24A4Y=; b=DUQr82lhB5vOVjAv3xnItHbYg8SASA4VMxByKWUO7DoJjcggfHt2jw9+aGyDArcZPS oL5TXgc3C67DWLDI1YxhzIAWBFwP/OAkeN4pfnH7oNW+L0GcrAR54uY79gkfYH8EAgub 1RmZdOYlu24xPAWaAuJVPW1tiQotw5q0H5BE+DlBJPA/jdeszOhFsmPR5kg8nYrlx8ye SaZ44znb9yoJ7mQBM/6znx5JHL94a804GtASfJTASIwRPwDtS7XL9gO1F5diZr/YDO/V a11Qqas4UhaPD1tQX3OcYzjkEcZ2wPRxkSUQ7/9+AcSZ5QAwih+yQ/GDl9TH/JtJ417p Qiww== |
| X-Gm-Message-State | APjAAAXyyIO9Z59myne0bFvoDCwlD6BDOTQMoG9+p6vmTmALOKTXUJlR wCB/xRNM5wwTBOk102MCBdGYtlxPCnwkNRkKaxaA6g== |
| X-Google-Smtp-Source | APXvYqy0VLm1qMcN26kQjkZUK0hHgBj65jFFNx3DZBQWBPD+nEKQS0zLq6JcOL8Sr9GnASjlEWkWwYCsFklwk2u6lxY= |
| X-Received | by 2002:a81:4b45:: with SMTP id y66mr4488211ywa.280.1564506544844; Tue, 30 Jul 2019 10:09:04 -0700 (PDT) |
| X-detected-operating-system | by eggs.gnu.org: Genre and OS details not recognized. |
| X-Received-From | 2607:f8b0:4864:20::c34 |
| X-Mailman-Approved-At | Tue, 30 Jul 2019 13:32:28 -0400 |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.23 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CANY-LFLTkqOyooA522KwuB1JEiaiUQ=N-5XEVWxueO14WLWWvQ@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:15280 |
Show key headers only | View raw
So I think I've discovered a bug with the way that bash handles passing
argc and argv to programs in the presence of multiple redirects.
For this testing, my C source file is just the following:
int main(int argc, char * argv[]) {
return argc;
}
For the purposes of testing, I comment out one or the other of those lines
and run the following:
./a.out; echo $?
returns 1 as expected
./a.out foo; echo $?
returns 2 as expected
./a.out foo > /dev/null; echo $?
returns 2 as expected
./a.out foo > /dev/null 2&>1; echo $?
returns 3 NOT as expected
If I modify and recompile the program to return the contents of argv I can
see that the contents of that 3rd argument is the string "2".
This behavior was tested and not observed with zsh and seems dangerous
(since a program taking variable length arguments might behave differently
only when the user tries to silence output). I could /maybe/ see an
argument for it being the string "2&>1" but "2" is very much incorrect.
I've tested on:
OSX 10.14.6 with the provided bash shell:
"GNU bash, 3.2.57(1)-release (x86_64-apple-darwin18)"
as well as latest from brew:
"GNU bash, version 5.0.7(1)-release (x86_64-apple-darwin18.5.0)"
Also reproduced on CentOS:
"2.6.32-504.30.3.el6.x86_64 #1 SMP Wed Jul 15 10:13:09 UTC 2015 x86_64
x86_64 x86_64 GNU/Linux"
"GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)"
Is this known behavior? I've been unable to locate documentation to this
effect and it seems highly unexpected especially given that other shells
don't appear to do it.
-Morgan
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Incorrect passing of argc argv with multiple redirects Morgan McClure <mcclure.morgan@gmail.com> - 2019-07-30 10:08 -0700
csiph-web