jonschipp / systemsprogramming

System programming examples
GNU General Public License v2.0
1 stars 0 forks source link

[BUG] tee: strange file created #1

Open lbontu opened 8 years ago

lbontu commented 8 years ago

Something strange is going on. I'll dive into the code later to try and help. I'm guessing the actual problem has something to do with options handling? Here's how to recreate what I am seeing:

Everything works as expected with normal usage:

$ ls -1
tee
tee.c
$ ./tee -af out.txt
foo
foo
^D
$ ls -1
out.txt
tee
tee.c

But, if you abuse the options handling a bit and don't provide an output file, this weird file shows up.

$ ls -1
tee
tee.c
$ ./tee -a
foo
foo
^D
$ ls -1
1?I??^H??H???PTI??0?@
tee
tee.c

*short_options contains a seemingly unhandled -o option, and this can trigger the issue as well.

$ ls -1
tee
tee.c
$ ./tee -o blah
foo
foo
^D
$ ls -1
1?I??^H??H???PTI??0?@
tee
tee.c
jonschipp commented 8 years ago

What happens when you set LANC=C?

On Fri, Dec 11, 2015 at 2:20 PM, lbontu notifications@github.com wrote:

Something strange is going on I'll dive into the code later to try and help I'm guessing the actual problem has something to do with options handling? Here's how to recreate what I am seeing:

Everything works as expected with normal usage:

$ /tee -af outtxt foo foo ^D $ ls -1 outtxt tee teec

But, if you abuse the options handling a bit and don't provide an output file, this weird file shows up

$ ls -1 tee teec $ /tee -a foo foo ^D $ ls -1 1?I??^H??H???PTI??0?@ tee teec

*short_options contains a seemingly unhandled '-o' option, and this can trigger the issue as well

$ ls -1 tee teec $ /tee -o blah foo foo ^D $ ls -1 1?I??^H??H???PTI??0?@ tee teec

— Reply to this email directly or view it on GitHub https://github.com/jonschipp/systemsprogramming/issues/1.

Jon Schipp, jonschipp.com, sickbits.net, http://goog_1056813495open-nsm.net,

lbontu commented 8 years ago

Same thing:

$ export LANG=C
$ rm -f 1*
$ ./tee -a 
foo
foo
$ ls
1?I??^H??H???PTI??0?@  tee  tee.c

Do you experience this behavior on your machine? Here is the actual filename, if you're curious:

$ ls 1* | cut -c3- | hexdump -C
00000000  49 89 d1 5e 48 89 e2 48  83 e4 f0 50 54 49 c7 c0  |I..^H..H...PTI..|
00000010  30 09 40 0a                                       |0.@.|
jonschipp commented 8 years ago

I patched the unhandled o option, thanks. Our output differs, what's your system info? Looks like I need required or make a condition for the absence of a file argument. ./tee1 -a open: Bad address foo write: Bad file descriptor foo foo write: Bad file descriptor foo close: Bad file descriptor

On Fri, Dec 11, 2015 at 2:36 PM, lbontu notifications@github.com wrote:

Same thing:

$ export LANG=C $ rm -f 1* $ ./tee -a foo foo $ ls 1?I??^H??H???PTI??0?@ tee tee.c

— Reply to this email directly or view it on GitHub https://github.com/jonschipp/systemsprogramming/issues/1#issuecomment-164041848 .

Jon Schipp, jonschipp.com, sickbits.net, http://goog_1056813495open-nsm.net,

lbontu commented 8 years ago

Here's some system information:

$ uname -mor
2.6.32-504.3.3.el6.x86_64 x86_64 GNU/Linux
$ ldd --version | head -n1
ldd (GNU libc) 2.12
$ lsb_release -d
Description:    Scientific Linux release 6.7 (Carbon)

Maybe open() is weird on this system?