Hi,

While working on file(1) for permit standard input type determination, I
investigate why when /dev/stdin is used, the output was 'data'.

It seems that the fill_buffer function don't adjust inf->size to readed
buffer. So the test_file function may operate on larger buffer than
expected, considering garbage as potential data.

before:
-------
$ echo foobar | file -s /dev/stdin
/dev/stdin: data

after:
------
$ echo foobar | file -s /dev/stdin
/dev/stdin: ASCII text

Thanks.
-- 
Sébastien Marie


Index: file.c
===================================================================
RCS file: /cvs/src/usr.bin/file/file.c,v
retrieving revision 1.39
diff -u -p -r1.39 file.c
--- file.c      28 May 2015 19:26:37 -0000      1.39
+++ file.c      29 May 2015 10:23:17 -0000
@@ -398,6 +409,7 @@ fill_buffer(struct input_file *inf)
                left -= got;
        }
 
+       inf->size -= left;
        return buffer;
 }
 

Reply via email to