Module Name:    othersrc
Committed By:   lukem
Date:           Sat Sep 23 02:30:54 UTC 2023

Modified Files:
        othersrc/libexec/tnftpd/libnetbsd: inet_pton.c

Log Message:
sync lib/libc/inet/inet_pton.c 1.8

Functional changes since upstream 1.3:
- 1.8: fix lint issues
- 1.4: hex formatting change from bind 9.4.0

Retain tnftpd local changes:
- 1.3: don't use non-standard u_char u_int u_int32_t
- 1.1: only enable IPv6 ifdef INET6.

Comment out other unneeded upstream code to minimise differences.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 othersrc/libexec/tnftpd/libnetbsd/inet_pton.c

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

Modified files:

Index: othersrc/libexec/tnftpd/libnetbsd/inet_pton.c
diff -u othersrc/libexec/tnftpd/libnetbsd/inet_pton.c:1.4 othersrc/libexec/tnftpd/libnetbsd/inet_pton.c:1.5
--- othersrc/libexec/tnftpd/libnetbsd/inet_pton.c:1.4	Sun Sep 21 16:35:25 2008
+++ othersrc/libexec/tnftpd/libnetbsd/inet_pton.c	Sat Sep 23 02:30:54 2023
@@ -1,5 +1,7 @@
-/* $NetBSD: inet_pton.c,v 1.4 2008/09/21 16:35:25 lukem Exp $ */
-/* from	NetBSD: inet_pton.c,v 1.3 2006/09/26 05:59:18 lukem Exp */
+/* $NetBSD: inet_pton.c,v 1.5 2023/09/23 02:30:54 lukem Exp $ */
+
+/* from:	NetBSD: inet_pton.c,v 1.8 2012/03/13 21:13:38 christos Exp */
+/* upstream:	lib/libc/inet/inet_pton.c */
 
 /*
  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -20,7 +22,39 @@
 
 #include "tnftpd.h"
 
-/*
+#if 0
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static const char rcsid[] = "Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp";
+#else
+__RCSID("$NetBSD: inet_pton.c,v 1.5 2023/09/23 02:30:54 lukem Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "port_before.h"
+
+#include "namespace.h"
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+#include <stddef.h>
+#include <string.h>
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include "port_after.h"
+
+#ifdef __weak_alias
+__weak_alias(inet_pton,_inet_pton)
+#endif
+#endif
+
+/*%
  * WARNING: Don't even consider trying to compile this on a system where
  * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
  */
@@ -45,6 +79,9 @@ int
 inet_pton(int af, const char *src, void *dst)
 {
 
+	_DIAGASSERT(src != NULL);
+	_DIAGASSERT(dst != NULL);
+
 	switch (af) {
 	case AF_INET:
 		return (inet_pton4(src, dst, 1));
@@ -75,10 +112,13 @@ inet_pton4(const char *src, unsigned cha
 {
 	uint32_t val;
 	unsigned int digit, base;
-	int n;
+	ptrdiff_t n;
 	unsigned char c;
 	unsigned int parts[4];
-	register unsigned int *pp = parts;
+	unsigned int *pp = parts;
+
+	_DIAGASSERT(src != NULL);
+	_DIAGASSERT(dst != NULL);
 
 	c = *src;
 	for (;;) {
@@ -198,9 +238,12 @@ inet_pton6(const char *src, unsigned cha
 			  xdigits_u[] = "0123456789ABCDEF";
 	unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
 	const char *xdigits, *curtok;
-	int ch, saw_xdigit;
+	int ch, seen_xdigits;
 	unsigned int val;
 
+	_DIAGASSERT(src != NULL);
+	_DIAGASSERT(dst != NULL);
+
 	memset((tp = tmp), '\0', NS_IN6ADDRSZ);
 	endp = tp + NS_IN6ADDRSZ;
 	colonp = NULL;
@@ -209,7 +252,7 @@ inet_pton6(const char *src, unsigned cha
 		if (*++src != ':')
 			return (0);
 	curtok = src;
-	saw_xdigit = 0;
+	seen_xdigits = 0;
 	val = 0;
 	while ((ch = *src++) != '\0') {
 		const char *pch;
@@ -218,15 +261,14 @@ inet_pton6(const char *src, unsigned cha
 			pch = strchr((xdigits = xdigits_u), ch);
 		if (pch != NULL) {
 			val <<= 4;
-			val |= (pch - xdigits);
-			if (val > 0xffff)
+			val |= (int)(pch - xdigits);
+			if (++seen_xdigits > 4)
 				return (0);
-			saw_xdigit = 1;
 			continue;
 		}
 		if (ch == ':') {
 			curtok = src;
-			if (!saw_xdigit) {
+			if (!seen_xdigits) {
 				if (colonp)
 					return (0);
 				colonp = tp;
@@ -237,19 +279,19 @@ inet_pton6(const char *src, unsigned cha
 				return (0);
 			*tp++ = (unsigned char) (val >> 8) & 0xff;
 			*tp++ = (unsigned char) val & 0xff;
-			saw_xdigit = 0;
+			seen_xdigits = 0;
 			val = 0;
 			continue;
 		}
 		if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
 		    inet_pton4(curtok, tp, 1) > 0) {
 			tp += NS_INADDRSZ;
-			saw_xdigit = 0;
-			break;	/* '\0' was seen by inet_pton4(). */
+			seen_xdigits = 0;
+			break;	/*%< '\\0' was seen by inet_pton4(). */
 		}
 		return (0);
 	}
-	if (saw_xdigit) {
+	if (seen_xdigits) {
 		if (tp + NS_INT16SZ > endp)
 			return (0);
 		*tp++ = (unsigned char) (val >> 8) & 0xff;
@@ -260,7 +302,7 @@ inet_pton6(const char *src, unsigned cha
 		 * Since some memmove()'s erroneously fail to handle
 		 * overlapping regions, we'll do the shift by hand.
 		 */
-		const int n = tp - colonp;
+		const ptrdiff_t n = tp - colonp;
 		int i;
 
 		if (tp == endp)
@@ -277,3 +319,5 @@ inet_pton6(const char *src, unsigned cha
 	return (1);
 }
 #endif /* INET6 */
+
+/*! \file */

Reply via email to