NetBSD Problem Report #48585

From www@NetBSD.org  Mon Feb 10 11:38:42 2014
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 907ACA645E
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 10 Feb 2014 11:38:42 +0000 (UTC)
Message-Id: <20140210113840.93CE7A64B4@mollari.NetBSD.org>
Date: Mon, 10 Feb 2014 11:38:40 +0000 (UTC)
From: henning.petersen@t-online.de
Reply-To: henning.petersen@t-online.de
To: gnats-bugs@NetBSD.org
Subject: Set errno if return is NULL in inet_ntop.c  
X-Send-Pr-Version: www-1.0

>Number:         48585
>Category:       lib
>Synopsis:       Set errno if return is NULL in inet_ntop.c
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 10 11:40:00 +0000 2014
>Closed-Date:    Sat Feb 22 17:33:52 +0000 2014
>Last-Modified:  Fri Mar 02 06:35:01 +0000 2018
>Originator:     Henning Petersen
>Release:        NetBSD-current
>Organization:
>Environment:
>Description:
Set errno if return is NULL in inet_ntop.c .
Test if inet_ntop4 is NULL in inet_ntop6 .
>How-To-Repeat:

>Fix:
diff -u -r1.9 inet_ntop.c
--- lib/libc/inet/inet_ntop.c	20 Mar 2012 17:08:13 -0000	1.9
+++ lib/libc/inet/inet_ntop.c	10 Feb 2014 07:23:16 -0000
@@ -188,8 +188,10 @@
 		}
 		/* Are we following an initial run of 0x00s or any real hex? */
 		if (i != 0) {
-			if (tp + 1 >= ep)
+			if (tp + 1 >= ep) {
+				errno = ENOSPC;
 				return (NULL);
+			}
 			*tp++ = ':';
 		}
 		/* Is this address an encapsulated IPv4? */
@@ -197,25 +199,33 @@
 		    (best.len == 6 ||
 		    (best.len == 7 && words[7] != 0x0001) ||
 		    (best.len == 5 && words[5] == 0xffff))) {
-			if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
+			if (inet_ntop4(src+12, tp, (socklen_t)(ep - tp))==NULL){
+				errno = ENOSPC;
 				return (NULL);
+			}
 			tp += strlen(tp);
 			break;
 		}
 		advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
-		if (advance <= 0 || advance >= ep - tp)
+		if (advance <= 0 || advance >= ep - tp) {
+			errno = ENOSPC;
 			return (NULL);
+		}
 		tp += advance;
 	}
 	/* Was it a trailing run of 0x00's? */
 	if (best.base != -1 && (best.base + best.len) == 
 	    (NS_IN6ADDRSZ / NS_INT16SZ)) {
-		if (tp + 1 >= ep)
+		if (tp + 1 >= ep) {
+			errno = ENOSPC;
 			return (NULL);
+		}
 		*tp++ = ':';
 	}
-	if (tp + 1 >= ep)
+	if (tp + 1 >= ep) {
+		errno = ENOSPC;
 		return (NULL);
+	}
 	*tp++ = '\0';

 	/*

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/48585 CVS commit: src/lib/libc/inet
Date: Mon, 10 Feb 2014 11:29:30 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Mon Feb 10 16:29:30 UTC 2014

 Modified Files:
 	src/lib/libc/inet: inet_ntop.c

 Log Message:
 PR/48585: Henning Petersen: Always set errno when returning NULL.


 To generate a diff of this commit:
 cvs rdiff -u -r1.9 -r1.10 src/lib/libc/inet/inet_ntop.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Sat, 22 Feb 2014 17:33:52 +0000
State-Changed-Why:
Christos committed it


From: "Luke Mewburn" <lukem@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/48585 CVS commit: src/lib/libc/inet
Date: Fri, 2 Mar 2018 06:31:53 +0000

 Module Name:	src
 Committed By:	lukem
 Date:		Fri Mar  2 06:31:53 UTC 2018

 Modified Files:
 	src/lib/libc/inet: inet_ntop.c

 Log Message:
 PR/48585: Set errno when returning NULL for AF_INET

 In inet_ntop4(), errno wasn't set before returning NULL.
 Seems like an oversight in the existing fix for PR/48585.
 Noticed by code inspection.


 To generate a diff of this commit:
 cvs rdiff -u -r1.11 -r1.12 src/lib/libc/inet/inet_ntop.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.