[Bug 7784] New: diff applet fails to compare stdin and empty file

bugzilla at busybox.net bugzilla at busybox.net
Wed Jan 7 17:21:00 UTC 2015


           Summary: diff applet fails to compare stdin and empty file
           Product: Busybox
           Version: 1.21.x
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: minor
          Priority: P5
         Component: Standard Compliance
        AssignedTo: unassigned at busybox.net
        ReportedBy: rekjanov at epiphan.com
                CC: busybox-cvs at busybox.net
   Estimated Hours: 0.0

#touch empty_file
#echo something | busybox diff empty_file -

expected (diff -u from diffutils):

--- empty_file  2015-01-07 11:59:45.196702422 -0500
+++ -   2015-01-07 11:59:52.310080775 -0500
@@ -0,0 +1 @@

and diff returns 1 (files differ)

actual result with busybox's diff:
no output and diff returns 0 (files are same)

This is because diffreg function copies stdin into a temporary file and leaves
the file pointer at the end of that file, so both i and j are 0 after first
read, i is 0 because the file is empty and j is 0 because the file is EOF

i = fread(buf0, 1, sz, fp[0]);
j = fread(buf1, 1, sz, fp[1]);

As a result, the files are deemed same.

A lseek on fd_tmp or fseek on fp[1] after fdopen should fix this.

BTW, the man page for fopen/fdopen is a bit misleading as one can assume that
fdopen with "r" would rewind the file, but the opengroup documentation for
fdopen explicitely says:
The file position indicator associated with the new stream is set to the
position indicated by the file offset associated with the file descriptor.


Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the busybox-cvs mailing list