Date: Thu, 12 Jun 1997 17:53:15 -0400 (EDT) From: metcalf@snet.net To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/3855: /usr/bin/cmp fails with nonzero byte offsets Message-ID: <199706122153.RAA00636@katya.snet.net> Resent-Message-ID: <199706122200.PAA23329@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 3855 >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: Thu Jun 12 15:00:01 PDT 1997 >Last-Modified: >Originator: Jeffrey M. Metcalf >Organization: Jeffrey M. Metcalf >Release: FreeBSD 2.2.1-RELEASE i386 >Environment: System: FreeBSD 2.2.1-RELEASE Architecture: Intel i386 >Description: This is a followup to a previous send-pr, identification bin/3850. It provides a revised patch similar to the source code in /usr/bin/cmp in the FreeBSD-3.0 SNAP release. The base conversion problem is still an issue in the 3.0 code. /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 Thu Jun 12 13:03:06 1997 --- cmp.c Thu Jun 12 13:18:40 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 : 12-Jun-97 + * Re : Fix bug in 2.2-SOURCES in which cmp cannot deal with nonzero + * skip byte offsets due to mmap's inability to map non page + * aligned offsets. Also, cmp is supposed to allow byte offsets + * to be entered in decimal, hex, and octal according to cmp.1. + * Portions of 3.0-SOURCES used. */ *************** *** 121,126 **** } ! skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0; ! skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0; if (!special) { --- 131,141 ---- } ! /* ! * Use 0 as the base below to include hex and octal conversions. ! * JM, 12-JUN-97 ! */ ! ! 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 Thu Jun 12 13:03:06 1997 --- regular.c Thu Jun 12 13:21:19 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 : 12-Jun-97 + * Re : Fix bug in 2.2-SOURCES in which cmp cannot deal with nonzero + * skip byte offsets due to mmap's inability to map non page + * aligned offsets. Also, cmp is supposed to allow byte offsets + * to be entered in decimal, hex, and octal according to cmp.1. + * Portions of 3.0-SOURCES used. */ *************** *** 72,75 **** --- 82,89 ---- len2 -= skip2; + pagemask = (off_t)getpagesize() - 1; + off1 = ROUNDPAGE(skip1); + off2 = ROUNDPAGE(skip2); + length = MIN(len1, len2); if (length > SIZE_T_MAX) *************** *** 77,87 **** 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) --- 91,103 ---- if ((p1 = (u_char *)mmap(NULL, ! (size_t)length, PROT_READ, 0, fd1, off1)) == (u_char *)-1) err(ERR_EXIT, "%s", file1); if ((p2 = (u_char *)mmap(NULL, ! (size_t)length, PROT_READ, 0, fd2, off2)) == (u_char *)-1) err(ERR_EXIT, "%s", file2); dfound = 0; + p1 += skip1 - off1; + p2 += skip2 - off2; for (byte = line = 1; length--; ++p1, ++p2, ++byte) { if ((ch = *p1) != *p2) >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199706122153.RAA00636>