NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/55916: cmp -s + regular files + skipping is broken



>Number:         55916
>Category:       bin
>Synopsis:       cmp -s + regular files + skipping is broken
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 09 11:00:01 +0000 2021
>Originator:     William Ahern
>Release:        MAIN
>Organization:
>Environment:
>Description:
NetBSD failed to pick-up a June 2000 (20-year-old) FreeBSD bugfix to the short-circuit in regular.c:c_regular of cmp(1). See https://svnweb.freebsd.org/base/head/usr.bin/cmp/regular.c?revision=61883&view=markup

OpenBSD had the same problem but the fix was just committed today, January 9, 2021. See misc%openbsd.org@localhost thread at https://marc.info/?t=161016193400003&r=1&w=2

Note that FreeBSD accidentally reintroduced the same bug a month later (July 2000) when they added -z support. See my report at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252542 Be careful if resync'ing to FreeBSD. DragonflyBSD inherited the FreeBSD regression.

>How-To-Repeat:
Run and compare

$ cmp file1 file2 skip1 skip2

with

$ cmp -s file1 file2 skip1 skip2

where file1 and file2 are regular files, skip1 and skip2 are different, and cmp should be expected to succeed with exit status 0 because the trailing data is identical. The former succeeds but the latter (cmp -s) will fail.

See example code snippet in original OpenBSD report at https://marc.info/?l=openbsd-misc&m=161016188503894&w=2

>Fix:
Move the short-circuit exit in regular.c:c_regular to after len1 and len2 are reduced by skip1 and skip2. See https://svnweb.freebsd.org/base/head/usr.bin/cmp/regular.c?revision=61883&view=markup and https://marc.info/?l=openbsd-misc&m=161017560806516&w=2



Home | Main Index | Thread Index | Old Index