NetBSD Problem Report #55916

From  Sat Jan  9 10:58:50 2021
Return-Path: <>
Received: from ( [])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "", Issuer " CA" (not verified))
	by (Postfix) with ESMTPS id 248441A9245
	for <>; Sat,  9 Jan 2021 10:58:50 +0000 (UTC)
Message-Id: <>
Date: Sat,  9 Jan 2021 10:58:48 +0000 (UTC)
Subject: cmp -s + regular files + skipping is broken
X-Send-Pr-Version: www-1.0

>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
>Last-Modified:  Sat Jan 09 15:20:01 +0000 2021
>Originator:     William Ahern
>Release:        MAIN
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

OpenBSD had the same problem but the fix was just committed today, January 9, 2021. See thread at

Note that FreeBSD accidentally reintroduced the same bug a month later (July 2000) when they added -z support. See my report at Be careful if resync'ing to FreeBSD. DragonflyBSD inherited the FreeBSD regression.

Run and compare

$ cmp file1 file2 skip1 skip2


$ 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

Move the short-circuit exit in regular.c:c_regular to after len1 and len2 are reduced by skip1 and skip2. See and

From: "Christos Zoulas" <>
Subject: PR/55916 CVS commit: src/usr.bin/cmp
Date: Sat, 9 Jan 2021 10:16:28 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sat Jan  9 15:16:28 UTC 2021

 Modified Files:
 	src/usr.bin/cmp: regular.c

 Log Message:
 PR/55916: William Ahern: cmp -s + regular files + skipping is broken
 Move test after length is adjusted

 To generate a diff of this commit:
 cvs rdiff -u -r1.24 -r1.25 src/usr.bin/cmp/regular.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD:,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.