From spatula@flag.blackened.net  Sat Oct 21 13:14:10 2000
Return-Path: <spatula@flag.blackened.net>
Received: from flag.blackened.net (flag.blackened.net [208.206.78.232])
	by hub.freebsd.org (Postfix) with ESMTP id 468B237B4D7
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 21 Oct 2000 13:14:10 -0700 (PDT)
Received: by flag.blackened.net (Postfix, from userid 1008)
	id C4B9E6790; Sat, 21 Oct 2000 13:14:09 -0700 (PDT)
Message-Id: <20001021201409.C4B9E6790@flag.blackened.net>
Date: Sat, 21 Oct 2000 13:14:09 -0700 (PDT)
From: freebsd@spatula.net
Sender: spatula@flag.blackened.net
Reply-To: freebsd@spatula.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: inet_ntop setting misleading errno, incompletely documented
X-Send-Pr-Version: 3.2

>Number:         22198
>Category:       bin
>Synopsis:       inet_ntop may set errno to ENOSPC and needs better docs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bms
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 21 13:20:01 PDT 2000
>Closed-Date:    Tue Dec 13 00:53:40 GMT 2005
>Last-Modified:  Tue Dec 13 00:53:40 GMT 2005
>Originator:     Nick Johnson
>Release:        FreeBSD 4.1.1-RELEASE i386
>Organization:
Spatula Systems
>Environment:

4.1.1-RELEASE

	

>Description:

Instead of setting a reasonable errno, inet_ntop will set errno
to ENOSPC (No space left on device) rather than something like
EINVAL or ENOMEM when the destination char * is not large enough
to contain the resulting address.  Further, it isn't clear from
the manpage if "size" is meant to be the size of the address
or the max size of the destination array (it is meant to be the latter).

	

>How-To-Repeat:

inet_ntop(AF_INET, some_address, some_char_array, 5);
perror("inet_ntop");

	

>Fix:

	

Possible fixes to inet_ntop.c and inet.3:


--- inet_ntop.c.orig	Sat Oct 21 13:02:52 2000
+++ inet_ntop.c	Sat Oct 21 13:02:04 2000
@@ -86,7 +86,7 @@
 	char tmp[sizeof "255.255.255.255"];
 
 	if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
-		errno = ENOSPC;
+		errno = EINVAL;
 		return (NULL);
 	}
 	strcpy(dst, tmp);
@@ -183,7 +183,7 @@
 	 * Check for overflow, copy, and we're done.
 	 */
 	if ((size_t)(tp - tmp) > size) {
-		errno = ENOSPC;
+		errno = EINVAL;
 		return (NULL);
 	}
 	strcpy(dst, tmp);


--- inet.3.orig	Sat Oct 21 13:02:33 2000
+++ inet.3	Sat Oct 21 13:02:04 2000
@@ -114,10 +114,16 @@
 .Pp
 The function
 .Fn inet_ntop
-converts an address from network format (usually a
+converts an address from network format specified by
+.Fa *src
+(usually a
 .Ft struct in_addr
-or some other binary form, in network byte order) to presentation format
-(suitable for external display purposes).
+or some other binary form, in network byte order) to presentation format in
+.Fa *dst
+(suitable for external display purposes). The max size of 
+.Fa *dst
+is specified by 
+.Fa size
 It returns NULL if a system error occurs (in which case,
 .Va errno
 will have been set), or it returns a pointer to the destination string.
@@ -221,6 +227,15 @@
 and
 .Fn inet_network
 for malformed requests.
+.Sh ERRORS
+The
+.Fn inet_pton
+call fails if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+.Fa size
+was not large enough to store the presentation form of the address.
+.El
 .Sh SEE ALSO
 .Xr addr2ascii 3 ,
 .Xr gethostbyname 3 ,

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->freebsd-bugs 
Responsible-Changed-By: dcs 
Responsible-Changed-When: Sat Oct 21 13:33:04 PDT 2000 
Responsible-Changed-Why:  
Moved from pending. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22198 
State-Changed-From-To: open->patched 
State-Changed-By: bms 
State-Changed-When: Mon Jun 14 14:18:41 GMT 2004 
State-Changed-Why:  
I'll take this. Committed to HEAD with some cleanups. 


Responsible-Changed-From-To: freebsd-bugs->bms 
Responsible-Changed-By: bms 
Responsible-Changed-When: Mon Jun 14 14:18:41 GMT 2004 
Responsible-Changed-Why:  
I'll take this. Committed to HEAD with some cleanups. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22198 
State-Changed-From-To: patched->closed 
State-Changed-By: bms 
State-Changed-When: Tue Dec 13 00:53:30 UTC 2005 
State-Changed-Why:  
-CURRENT is now -STABLE 


http://www.freebsd.org/cgi/query-pr.cgi?pr=22198 
>Unformatted:
