From jeff@katya.snet.net  Wed Jun 11 19:40:03 1997
Received: from katya.snet.net (hrfr03-sh1-port17.snet.net [204.60.8.17])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id TAA00830
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 11 Jun 1997 19:39:54 -0700 (PDT)
Received: (from jeff@localhost) by katya.snet.net (8.8.5/8.7.3) id WAA01190; Wed, 11 Jun 1997 22:39:41 -0400 (EDT)
Message-Id: <199706120239.WAA01190@katya.snet.net>
Date: Wed, 11 Jun 1997 22:39:41 -0400 (EDT)
From: metcalf@snet.net
Reply-To: metcalf@snet.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: /usr/bin/cmp fails with nonzero byte offsets 
X-Send-Pr-Version: 3.2

>Number:         3850
>Category:       bin
>Synopsis:       /usr/bin/cmp fails with nonzero byte offsets
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 11 19:50:01 PDT 1997
>Closed-Date:    Tue Aug 19 07:34:09 PDT 1997
>Last-Modified:  Tue Aug 19 07:37:50 PDT 1997
>Originator:     Jeffrey M. Metcalf
>Release:        FreeBSD 2.2.1-RELEASE i386
>Organization:
>Environment:
System: FreeBSD 2.2.1-RELEASE
Architecture: Intel i386

>Description:
	/usr/bin/cmp fails to perform according to the manual page
	cmp.1 in that nonzero values of skip1 and skip2 for the
	byte offsets results in an 'Invalid argument' error.
	This seems to be due to the fact that the mmap system
	call fails for non page aligned offsets.  Also, only
	base 10 conversion is allowed whereas the manual page 
	implies that octal and hexadecimal byte offsets can be
	entered.

>How-To-Repeat:
	prompt% /usr/bin/cmp file1 file2 skip1 skip2

	where skip1 and skip2 are nonzero byte offsets
	into file1 and file2 respectively.

>Fix:
	Apply the following patch to the sources in the 
	/usr/src/usr.bin/cmp directory:


*** /usr/src/usr.bin/cmp/cmp.c	Wed Jun 11 21:28:24 1997
--- cmp.c	Wed Jun 11 21:36:25 1997
***************
*** 30,35 ****
--- 30,46 ----
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
+  *
+  *
+  * Update:
+  *
+  * Author: Jeffrey M. Metcalf
+  * Date  : 11-Jun-97
+  * Re    : /usr/bin/cmp did not work as described in cmp.1
+  *	   Nonzero values for skip1 and skip2 fail since 
+  *	   the mmap function call can only deal with page 
+  *	   aligned file offsets.
   */
  
+ 
  #ifndef lint
  static char copyright[] =
***************
*** 121,126 ****
  	}
  
! 	skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0;
! 	skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0;
  
  	if (!special) {
--- 132,141 ----
  	}
  
! /*
!  *  Make sure base in the following function is 0 so that we
!  *  can enter decimal, octal, and hex skip values.
!  */
! 	skip1 = argc > 2 ? strtol(argv[2], NULL, 0) : 0;
! 	skip2 = argc == 4 ? strtol(argv[3], NULL, 0) : 0;
  
  	if (!special) {
*** /usr/src/usr.bin/cmp/regular.c	Wed Jun 11 21:28:24 1997
--- regular.c	Wed Jun 11 21:40:32 1997
***************
*** 30,33 ****
--- 30,43 ----
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
+  *
+  *
+  * Update:
+  *
+  * Author: Jeffrey M. Metcalf
+  * Date  : 11-Jun-97
+  * Re    : /usr/bin/cmp did not work as described in cmp.1
+  *         Nonzero values for skip1 and skip2 fail since 
+  *         the mmap function call can only deal with page 
+  *         aligned file offsets.
   */
  
***************
*** 77,92 ****
  
  	if ((p1 = (u_char *)mmap(NULL,
! 	    (size_t)length, PROT_READ, 0, fd1, skip1)) == (u_char *)-1)
  		err(ERR_EXIT, "%s", file1);
  	if ((p2 = (u_char *)mmap(NULL,
! 	    (size_t)length, PROT_READ, 0, fd2, skip2)) == (u_char *)-1)
  		err(ERR_EXIT, "%s", file2);
  
  	dfound = 0;
  	for (byte = line = 1; length--; ++p1, ++p2, ++byte) {
! 		if ((ch = *p1) != *p2)
  			if (lflag) {
  				dfound = 1;
! 				(void)printf("%6qd %3o %3o\n", byte, ch, *p2);
  			} else
  				diffmsg(file1, file2, byte, line);
--- 87,103 ----
  
  	if ((p1 = (u_char *)mmap(NULL,
! 	    (size_t)length, PROT_READ, 0, fd1, 0)) == (u_char *)-1)
  		err(ERR_EXIT, "%s", file1);
  	if ((p2 = (u_char *)mmap(NULL,
! 	    (size_t)length, PROT_READ, 0, fd2, 0)) == (u_char *)-1)
  		err(ERR_EXIT, "%s", file2);
  
  	dfound = 0;
  	for (byte = line = 1; length--; ++p1, ++p2, ++byte) {
! 		if ((ch = *(p1+skip1)) != *(p2+skip2))
  			if (lflag) {
  				dfound = 1;
! 				(void)printf("%6qd %3o %3o\n", byte, ch, 
! 				   *(p2+skip2));
  			} else
  				diffmsg(file1, file2, byte, line);

>Release-Note:
>Audit-Trail:

From: "Jeffrey M. Metcalf" <metcalf@snet.net>
To: <freebsd-gnats-submit@freebsd.org>
Cc:  Subject: Re: bin/3850: /usr/bin/cmp fails with nonzero byte offsets
Date: Fri, 13 Jun 1997 04:01:21 -0400

 See bin/3855 for a follow up patch incorporating elements of 3.0-CURRENT
 sources.
 -----
 Jeffrey M. Metcalf
 metcalf@snet.net
 
 http://ruddles.stat.uconn.edu/~jeff
 
State-Changed-From-To: open->closed 
State-Changed-By: jlemon 
State-Changed-When: Tue Aug 19 07:34:09 PDT 1997 
State-Changed-Why:  

Argument conversion problem fixed, offset problem already taken care of. 
>Unformatted:
