Date: Wed, 11 Jun 1997 22:39:41 -0400 (EDT) From: metcalf@snet.net To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/3850: /usr/bin/cmp fails with nonzero byte offsets Message-ID: <199706120239.WAA01190@katya.snet.net> Resent-Message-ID: <199706120250.TAA01318@hub.freebsd.org>
index | next in thread | raw e-mail
>Number: 3850
>Category: bin
>Synopsis: /usr/bin/cmp fails with nonzero byte offsets
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Jun 11 19:50:01 PDT 1997
>Last-Modified:
>Originator: Jeffrey M. Metcalf
>Organization:
>Release: FreeBSD 2.2.1-RELEASE i386
>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);
>Audit-Trail:
>Unformatted:
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199706120239.WAA01190>
