From marcs@alive.znep.com Sat Oct 16 11:45:33 1999
Return-Path: <marcs@alive.znep.com>
Received: from alive.znep.com (alive.znep.com [207.167.15.58])
	by hub.freebsd.org (Postfix) with ESMTP id A926B1550C
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 16 Oct 1999 11:45:30 -0700 (PDT)
	(envelope-from marcs@alive.znep.com)
Received: (from marcs@localhost)
	by alive.znep.com (8.9.3/8.9.1) id MAA15590;
	Sat, 16 Oct 1999 12:45:30 -0600 (MDT)
	(envelope-from marcs)
Message-Id: <199910161845.MAA15590@alive.znep.com>
Date: Sat, 16 Oct 1999 12:45:30 -0600 (MDT)
From: Marc Slemko <marcs@alive.znep.com>
Reply-To: marcs@alive.znep.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: locate bogusly converts to network byte order in error messages
X-Send-Pr-Version: 3.2

>Number:         14361
>Category:       bin
>Synopsis:       locate bogusly converts to network byte order in error messages
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mikeh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 16 11:50:00 PDT 1999
>Closed-Date:    Wed Dec 12 17:49:14 PST 2001
>Last-Modified:  Wed Dec 12 17:49:27 PST 2001
>Originator:     Marc Slemko
>Release:        FreeBSD 3.3-STABLE i386
>Organization:
>Environment:

FreeBSD alive.znep.com 3.3-STABLE FreeBSD 3.3-STABLE #1: Sat Oct  2 10:03:23 MDT 1999     marcs@alive.znep.com:/usr/src/sys/compile/ALIVE  i386

>Description:

Locate tries to magically figure out what byte order the locate database
is in.  If the length of a path is not between -MAXPATHLEN and MAXPATHLEN,
it tries converting it from network to host byte order.  If that is
still bogus, it prints an error.  However, it prints the error using the
converted length, which results in something like:

locate: integer out of +-MAXPATHLEN (1024): 100925440

instead of:

locate: integer out of +-MAXPATHLEN (1024): 1030

in the normal case.  I think it is far more reasonble to assume that, if
it doesn't fit network or host byte order, then the host one should
be displayed in the error.  That isn't perfect either, but it is a more
common.  The whole concept of trying to magically figure out what byte
order to use is a bit bogus, but this change makes it so that users don't
see the odd results of it unless they are trying to use a database built
in network byte order.

>How-To-Repeat:

Create a pathname longer than MAXPATHLEN and get it into your locate
database.  Then when locate hits it, it will spit out an error.  

>Fix:
	

Index: util.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/locate/locate/util.c,v
retrieving revision 1.5.2.1
diff -u -r1.5.2.1 util.c
--- util.c	1999/08/29 15:29:53	1.5.2.1
+++ util.c	1999/10/16 18:26:19
@@ -241,7 +241,7 @@
 	if (i > MAXPATHLEN || i < -(MAXPATHLEN)) {
 		i = ntohl(i);
 		if (i > MAXPATHLEN || i < -(MAXPATHLEN))
-			errx(1, "integer out of +-MAXPATHLEN (%d): %d", MAXPATHLEN, i);
+			errx(1, "integer out of +-MAXPATHLEN (%d): %d", MAXPATHLEN, htonl(i));
 	}
 	return(i);
 }
@@ -265,7 +265,7 @@
 	if (word > MAXPATHLEN || word < -(MAXPATHLEN)) {
 		word = ntohl(word);
 		if (word > MAXPATHLEN || word < -(MAXPATHLEN))
-			errx(1, "integer out of +-MAXPATHLEN (%d): %d", MAXPATHLEN, word);
+			errx(1, "integer out of +-MAXPATHLEN (%d): %d", MAXPATHLEN, htonl(word));
 	}
 	return(word);
 }

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mikeh 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Thu Aug 16 09:21:57 PDT 2001 
Responsible-Changed-Why:  
I'll look into this. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=14361 
State-Changed-From-To: open->closed 
State-Changed-By: mikeh 
State-Changed-When: Wed Dec 12 17:49:14 PST 2001 
State-Changed-Why:  
Fix committed. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=14361 
>Unformatted:
