NetBSD Problem Report #23836

Received: (qmail 16678 invoked by uid 605); 22 Dec 2003 02:40:09 -0000
Message-Id: <20031222024009.16677.qmail@mail.netbsd.org>
Date: 22 Dec 2003 02:40:09 -0000
From: Christian Biere <christianbiere@gmx.de>
Sender: gnats-bugs-owner@NetBSD.org
To: gnats-bugs@gnats.netbsd.org
Subject: cmp doesn't handle skip parameters as documented
X-Send-Pr-Version: 3.95

>Number:         23836
>Category:       bin
>Synopsis:       cmp doesn't handle skip parameters as documented
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 22 02:41:00 +0000 2003
>Closed-Date:    Mon Sep 18 06:43:59 +0000 2006
>Last-Modified:  Mon Mar 19 07:10:03 +0000 2012
>Originator:     Christian Biere
>Release:        NetBSD 1.6ZG
>Organization:
>Environment:
System: NetBSD cyclonus 1.6ZG NetBSD 1.6ZG (STARSCREAM) #0: Tue Dec 16 17:11:50 CET 2003 bin@cyclonus:/usr/build/arch/i386/compile/STARSCREAM i386
Architecture: i386
Machine: i386
>Description:

The manpage of cmp(1) mentions that the parameters 'skip1' and 'skip2' maybe
given in decimal, hexadecimal or octal form. This isn't true. The code
handles and expects only decimal numbers. The code also doesn't perform any
error checking for these parameters so that you can easily pass obviously
wrong parameters without noticing it. The latter isn't strictly a bug - I
know. However, I see absolutely no reason for not adding it.

>How-To-Repeat:

$ echo 0123456789abcdef > a
$ echo abcdef > b
$ cmp a b '0xa' || echo MISMATCH
a b differ: char 1, line 1
MISMATCH

>Fix:

Index: cmp.c
===================================================================
RCS file: /cvsroot/src/usr.bin/cmp/cmp.c,v
retrieving revision 1.13
diff -u -u -r1.13 cmp.c
--- cmp.c	2003/08/07 11:13:22	1.13
+++ cmp.c	2003/12/22 02:23:20
@@ -47,6 +47,7 @@
 #include <sys/stat.h>

 #include <err.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -67,7 +68,7 @@
 	char *argv[];
 {
 	struct stat sb1, sb2;
-	off_t skip1, skip2;
+	off_t skip1 = 0, skip2 = 0;
 	int ch, fd1, fd2, special;
 	char *file1, *file2;

@@ -120,8 +121,20 @@
 		exit(ERR_EXIT);
 	}

-	skip1 = argc > 2 ? strtoq(argv[2], NULL, 10) : 0;
-	skip2 = argc == 4 ? strtoq(argv[3], NULL, 10) : 0;
+	if (argc > 2) {
+		char *ep;
+
+		errno = 0;
+		skip1 = strtoq(argv[2], &ep, 0);
+		if (errno || ep == argv[2])
+			usage();
+
+		if (argc == 4) {
+			skip2 = strtoq(argv[3], &ep, 0);
+			if (errno || ep == argv[3])
+				usage();
+		}
+	}

 	if (!special) {
 		if (fstat(fd1, &sb1))
>Release-Note:
>Audit-Trail:
From: Tim Rightnour <garbled@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: PR/23836 CVS commit: src/usr.bin/cmp
Date: Thu, 19 Jan 2006 20:44:57 +0000 (UTC)

 Module Name:	src
 Committed By:	garbled
 Date:		Thu Jan 19 20:44:57 UTC 2006

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

 Log Message:
 Apply patch from PR bin/23836  cmp did not correctly parse skip arguments
 given in hex or octal, as the manpage states it can.


 To generate a diff of this commit:
 cvs rdiff -r1.14 -r1.15 src/usr.bin/cmp/cmp.c

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

State-Changed-From-To: open->closed
State-Changed-By: dsl@netbsd.org
State-Changed-When: Mon, 18 Sep 2006 06:43:59 +0000
State-Changed-Why:
supplied patch applied.


From: "Jukka Ruohonen" <jruoho@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/23836 CVS commit: src
Date: Mon, 19 Mar 2012 07:05:19 +0000

 Module Name:	src
 Committed By:	jruoho
 Date:		Mon Mar 19 07:05:18 UTC 2012

 Modified Files:
 	src/distrib/sets/lists/tests: mi
 	src/etc/mtree: NetBSD.dist.tests
 	src/tests/usr.bin: Makefile
 Added Files:
 	src/tests/usr.bin/cmp: Makefile t_cmp.sh

 Log Message:
 Add regression tests for PR bin/2642 and PR bin/23836, both fixed long ago.


 To generate a diff of this commit:
 cvs rdiff -u -r1.450 -r1.451 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.66 -r1.67 src/etc/mtree/NetBSD.dist.tests
 cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/Makefile
 cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/cmp/Makefile \
     src/tests/usr.bin/cmp/t_cmp.sh

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

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.