Created attachment 390077 [details] patch to check for procfs Description of problem: 'cmp -s' tries to take a shortcut and compare file sizes before looking at their contents, and assumes if the file sizes are different, it can safely report that the files are different. This works in most cases, but it can fail with special filesystems like procfs where all files have a size of 0 bytes. For example, if you copy /proc/scsi/scsi to /tmp and then compare the two, it incorrectly reports that they are different. Version-Release number of selected component (if applicable): diffutils-2.8.1-15.2.3.el5.x86_64 How reproducible: every time Steps to Reproduce: 1. cp /proc/scsi/scsi /tmp 2. cmp -s /proc/scsi/scsi /tmp/scsi ; echo $? Actual results: exit status of 1 means the files are different (which is wrong) Expected results: exit status of 0 Additional info: Attached is a patch to skip the shortcut if either of the files being compared are contained within procfs.
Also note that cmp without the -s option works fine: $ cmp /proc/scsi/scsi /tmp/scsi ; echo $? 0 $ cmp -s /proc/scsi/scsi /tmp/scsi ; echo $? 1
I think it would be preferable to skip the check if either file is length 0. That takes care of procfs, sysfs, any other sensible on-demand type fs, avoids magic numbers, and adds very little overhead (1 syscall per file) in the case of real zero-length files.
Created attachment 390273 [details] patch to check for 0 byte files Good point, and the patch is actually much shorter and simpler this way.
This request was evaluated by Red Hat Product Management for inclusion in the current release of Red Hat Enterprise Linux. Because the affected component is not scheduled to be updated in the current release, Red Hat is unfortunately unable to address this request at this time. Red Hat invites you to ask your support representative to propose this request, if appropriate and relevant, in the next release of Red Hat Enterprise Linux.
This request was erroneously denied for the current release of Red Hat Enterprise Linux. The error has been fixed and this request has been re-proposed for the current release.
Technical note added. If any revisions are required, please edit the "Technical Notes" field accordingly. All revisions will be proofread by the Engineering Content Services team. New Contents: When using the cmp command's -s option to compare files, incorrect results would be returned for special files whose metadata is not accurate, such as files in the proc filesystem. This has been corrected by always reading the content of files whose length is reported as zero bytes.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. http://rhn.redhat.com/errata/RHBA-2013-0036.html