CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
Module Name:othersrc
Committed By:   lukem
Date:   Sat Sep 23 04:47:47 UTC 2023

Modified Files:
othersrc/libexec/tnftpd/libnetbsd: Makefile.am
Added Files:
othersrc/libexec/tnftpd/libnetbsd: libnetbsd.c

Log Message:
libnetbsd: add placeholder source to avoid an empty library


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

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



CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
Module Name:othersrc
Committed By:   lukem
Date:   Sat Sep 23 04:47:47 UTC 2023

Modified Files:
othersrc/libexec/tnftpd/libnetbsd: Makefile.am
Added Files:
othersrc/libexec/tnftpd/libnetbsd: libnetbsd.c

Log Message:
libnetbsd: add placeholder source to avoid an empty library


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 othersrc/libexec/tnftpd/libnetbsd/Makefile.am
cvs rdiff -u -r0 -r1.1 othersrc/libexec/tnftpd/libnetbsd/libnetbsd.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/Makefile.am
diff -u othersrc/libexec/tnftpd/libnetbsd/Makefile.am:1.4 othersrc/libexec/tnftpd/libnetbsd/Makefile.am:1.5
--- othersrc/libexec/tnftpd/libnetbsd/Makefile.am:1.4	Tue Jan 29 12:51:38 2019
+++ othersrc/libexec/tnftpd/libnetbsd/Makefile.am	Sat Sep 23 04:47:47 2023
@@ -1,8 +1,8 @@
-## $NetBSD: Makefile.am,v 1.4 2019/01/29 12:51:38 lukem Exp $
+## $NetBSD: Makefile.am,v 1.5 2023/09/23 04:47:47 lukem Exp $
 
 noinst_LTLIBRARIES = libnetbsd.la
 
-libnetbsd_la_SOURCES =
+libnetbsd_la_SOURCES = libnetbsd.c
 
 AM_CPPFLAGS = \
 	-DHAVE_TNFTPD_H=1 \

Added files:

Index: othersrc/libexec/tnftpd/libnetbsd/libnetbsd.c
diff -u /dev/null othersrc/libexec/tnftpd/libnetbsd/libnetbsd.c:1.1
--- /dev/null	Sat Sep 23 04:47:47 2023
+++ othersrc/libexec/tnftpd/libnetbsd/libnetbsd.c	Sat Sep 23 04:47:47 2023
@@ -0,0 +1,3 @@
+/* $NetBSD: libnetbsd.c,v 1.1 2023/09/23 04:47:47 lukem Exp $ */
+
+const char libnetbsd_placeholder[] = "Ensure libnetbsd.la is not empty";



CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
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 
+#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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#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 > 0x)
+			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 */



CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
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.



CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
Module Name:othersrc
Committed By:   lukem
Date:   Sat Sep 23 02:20:39 UTC 2023

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

Log Message:
sync lib/libc/inet/inet_ntop.c 1.12

Functional changes since upstream 1.3:
- 1.10, 1.12: always set errno when returning NULL

Retain tnftpd local changes:
- 1.3: don't use non-standard u_char u_int
- 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_ntop.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_ntop.c
diff -u othersrc/libexec/tnftpd/libnetbsd/inet_ntop.c:1.4 othersrc/libexec/tnftpd/libnetbsd/inet_ntop.c:1.5
--- othersrc/libexec/tnftpd/libnetbsd/inet_ntop.c:1.4	Sun Sep 21 16:35:25 2008
+++ othersrc/libexec/tnftpd/libnetbsd/inet_ntop.c	Sat Sep 23 02:20:39 2023
@@ -1,5 +1,7 @@
-/* $NetBSD: inet_ntop.c,v 1.4 2008/09/21 16:35:25 lukem Exp $ */
-/* from	NetBSD: inet_ntop.c,v 1.3 2006/05/10 21:53:15 mrg Exp */
+/* $NetBSD: inet_ntop.c,v 1.5 2023/09/23 02:20:39 lukem Exp $ */
+
+/* from:	NetBSD: inet_ntop.c,v 1.12 2018/03/02 06:31:53 lukem Exp */
+/* upstream:	lib/libc/inet/inet_ntop.c */
 
 /*
  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
@@ -20,7 +22,41 @@
 
 #include "tnftpd.h"
 
-/*
+#if 0
+#include 
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static const char rcsid[] = "Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp";
+#else
+__RCSID("$NetBSD: inet_ntop.c,v 1.5 2023/09/23 02:20:39 lukem Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "port_before.h"
+
+#include "namespace.h"
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "port_after.h"
+
+#ifdef __weak_alias
+__weak_alias(inet_ntop,_inet_ntop)
+#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.
  */
@@ -42,16 +78,19 @@ const char *
 inet_ntop(int af, const void *src, char *dst, socklen_t size)
 {
 
+	_DIAGASSERT(src != NULL);
+	_DIAGASSERT(dst != NULL);
+
 	switch (af) {
 	case AF_INET:
-		return (inet_ntop4(src, dst, size));
+		return inet_ntop4(src, dst, size);
 #ifdef INET6
 	case AF_INET6:
-		return (inet_ntop6(src, dst, size));
+		return inet_ntop6(src, dst, size);
 #endif /* INET6 */
 	default:
 		errno = EAFNOSUPPORT;
-		return (NULL);
+		return NULL;
 	}
 	/* NOTREACHED */
 }
@@ -73,14 +112,17 @@ inet_ntop4(const unsigned char *src, cha
 	char tmp[sizeof "255.255.255.255"];
 	int l;
 
+	_DIAGASSERT(src != NULL);
+	_DIAGASSERT(dst != NULL);
+
 	l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u",
 	src[0], src[1], src[2], src[3]);
 	if (l <= 0 || (socklen_t) l >= size) {
 		errno = ENOSPC;
-		return (NULL);
+		return NULL;
 	}
 	strlcpy(dst, tmp, size);
-	return (dst);
+	return dst;
 }
 
 #ifdef INET6
@@ -107,6 +149,9 @@ inet_ntop6(const unsigned char *src, cha
 	int i;
 	int advance;
 
+	_DIAGASSERT(src != NULL);
+	_DIAGASSERT(dst != NULL);
+
 	/*
 	 * Preprocess:
 	 *	Copy the input (bytewise) array into a wordwise array.
@@ -116,9 +161,9 @@ inet_ntop6(const unsigned char *src, cha
 	for (i = 0; i < NS_IN6ADDRSZ; i++)
 		words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
 	best.base = -1;
+	best.len = 0;
 	cur.base = -1;
-	best.len = -1;	/* XXX gcc */
-	cur.len = -1;	/* XXX gcc */
+	cur.len = 0;
 	for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
 		if (words[i] == 0) {
 			if (cur.base == -1)
@@ -156,7 +201,7 @@ inet_ntop6(const unsigned char *src, cha
 		/* Are we following an initial run of 0x00s or any real hex? */
 		if (i != 0) {
 			if (tp + 1 >= ep)
-return (NULL);
+goto out;
 			*tp++ = ':';
 		}
 		/* Is this address an encapsulated IPv4? */
@@ -164,35 +209,38 @@ inet_ntop6(const unsigned char *src, cha
 		(best.len == 6 ||
 		(best.len == 7 && words[7] != 0x0001) ||
 		(best.len == 5 && words[5] == 0x))) {
-			if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
-return (NULL);
+			if (!inet_ntop4(src + 12, tp, (socklen_t)(ep - tp)))
+goto out;
 			tp += strlen(tp);
 			break;
 		}
 		advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
 		if (advance <= 0 || advance >= ep - tp)
-			return (NULL);
+			goto out;
 		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)
-			return (NULL);
+			goto out;
 		*tp++ = ':';
 	}
 	if (tp + 1 >= ep)
-		return (NULL);
+		goto out;
 	*tp++ = '\0';
 
 	/*
 	 * Check for overflow, copy, and we're done.
 	 */
-	if ((size_t)(tp - tmp) > size) {
-		errno = ENOSPC;
-		return (NULL);
-	}
+	if ((size_t)(tp - tmp) > size)
+		goto out;
 	

CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
Module Name:othersrc
Committed By:   lukem
Date:   Sat Sep 23 02:20:39 UTC 2023

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

Log Message:
sync lib/libc/inet/inet_ntop.c 1.12

Functional changes since upstream 1.3:
- 1.10, 1.12: always set errno when returning NULL

Retain tnftpd local changes:
- 1.3: don't use non-standard u_char u_int
- 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_ntop.c

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



CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
Module Name:othersrc
Committed By:   lukem
Date:   Sat Sep 23 00:02:05 UTC 2023

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

Log Message:
sync lib/libc/inet/inet_net_pton.c 1.5

Functional changes since upstream 1.1:
- 1.3: fix lint issues
- 1.2: Check bits on each loop to prevent integer oveflow.

Retain tnftpd local changes:
- 1.3: don't use non-standard u_char u_int
- 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_net_pton.c

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



CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
Module Name:othersrc
Committed By:   lukem
Date:   Sat Sep 23 00:02:05 UTC 2023

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

Log Message:
sync lib/libc/inet/inet_net_pton.c 1.5

Functional changes since upstream 1.1:
- 1.3: fix lint issues
- 1.2: Check bits on each loop to prevent integer oveflow.

Retain tnftpd local changes:
- 1.3: don't use non-standard u_char u_int
- 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_net_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_net_pton.c
diff -u othersrc/libexec/tnftpd/libnetbsd/inet_net_pton.c:1.4 othersrc/libexec/tnftpd/libnetbsd/inet_net_pton.c:1.5
--- othersrc/libexec/tnftpd/libnetbsd/inet_net_pton.c:1.4	Sun Sep 21 16:35:25 2008
+++ othersrc/libexec/tnftpd/libnetbsd/inet_net_pton.c	Sat Sep 23 00:02:05 2023
@@ -1,5 +1,7 @@
-/* $NetBSD: inet_net_pton.c,v 1.4 2008/09/21 16:35:25 lukem Exp $ */
-/* from	NetBSD: inet_net_pton.c,v 1.1 2004/05/20 23:13:02 christos Exp */
+/* $NetBSD: inet_net_pton.c,v 1.5 2023/09/23 00:02:05 lukem Exp $ */
+
+/* from:	NetBSD: inet_net_pton.c,v 1.5 2018/12/13 08:44:11 maya Exp */
+/* upstream:	lib/libc/inet/inet_net_pton.c */
 
 /*
  * Copyright (c) 1996,1999 by Internet Software Consortium.
@@ -19,14 +21,42 @@
  */
 
 #include "tnftpd.h"
+#undef INSIST
+#define INSIST(x) /* */
 
-
-#ifdef SPRINTF_CHAR
-# define SPRINTF(x) strlen(sprintf/**/x)
+#if 0
+#include 
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static const char rcsid[] = "Id: inet_net_pton.c,v 1.4.2.1 2002/08/02 02:17:21 marka Exp ";
 #else
-# define SPRINTF(x) ((size_t)sprintf x)
+__RCSID(" NetBSD: inet_net_pton.c,v 1.5 2018/12/13 08:44:11 maya Exp  ");
+#endif
 #endif
 
+#include "port_before.h"
+
+#include "namespace.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "port_after.h"
+
+#ifdef __weak_alias
+__weak_alias(inet_net_pton,_inet_net_pton)
+#endif
+#endif
 
 /*
  * static int
@@ -45,12 +75,15 @@
  *	Paul Vixie (ISC), June 1996
  */
 static int
-inet_net_pton_ipv4( const char *src, unsigned char *dst, size_t size) {
+inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size)
+{
 	static const char xdigits[] = "0123456789abcdef";
 	static const char digits[] = "0123456789";
-	int n, ch, tmp = 0, dirty, bits;
+	int ch, dirty, bits;
+	ptrdiff_t n, tmp;
 	const unsigned char *odst = dst;
 
+	tmp = 0;
 	ch = *src++;
 	if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
 	&& isascii((unsigned char)(src[1]))
@@ -65,6 +98,7 @@ inet_net_pton_ipv4( const char *src, uns
 			if (isupper((unsigned char)ch))
 ch = tolower((unsigned char)ch);
 			n = strchr(xdigits, ch) - xdigits;
+			INSIST(n >= 0 && n <= 15);
 			if (dirty == 0)
 tmp = n;
 			else
@@ -87,13 +121,13 @@ inet_net_pton_ipv4( const char *src, uns
 			tmp = 0;
 			do {
 n = strchr(digits, ch) - digits;
+INSIST(n >= 0 && n <= 9);
 tmp *= 10;
 tmp += n;
 if (tmp > 255)
 	goto enoent;
 			} while ((ch = *src++) != '\0' &&
- isascii((unsigned char)ch) &&
- isdigit((unsigned char)ch));
+ isascii((unsigned char)ch) && isdigit((unsigned char)ch));
 			if (size-- == 0)
 goto emsgsize;
 			*dst++ = (unsigned char) tmp;
@@ -102,8 +136,7 @@ inet_net_pton_ipv4( const char *src, uns
 			if (ch != '.')
 goto enoent;
 			ch = *src++;
-			if (!isascii((unsigned char)ch) ||
-			!isdigit((unsigned char)ch))
+			if (!isascii((unsigned char)ch) || !isdigit((unsigned char)ch))
 goto enoent;
 		}
 	} else
@@ -117,14 +150,15 @@ inet_net_pton_ipv4( const char *src, uns
 		bits = 0;
 		do {
 			n = strchr(digits, ch) - digits;
+			INSIST(n >= 0 && n <= 9);
 			bits *= 10;
-			bits += n;
+			bits += (int)n;
+			if (bits > 32)
+goto emsgsize;
 		} while ((ch = *src++) != '\0' && isascii((unsigned char)ch)
 		&& isdigit((unsigned char)ch));
 		if (ch != '\0')
 			goto enoent;
-		if (bits > 32)
-			goto emsgsize;
 	}
 
 	/* Firey death and destruction unless we prefetched EOS. */
@@ -148,7 +182,7 @@ inet_net_pton_ipv4( const char *src, uns
 			bits = 8;
 		/* If imputed mask is narrower than specified octets, widen. */
 		if (bits >= 8 && bits < ((dst - odst) * 8))
-			bits = (dst - odst) * 8;
+			bits = (int)(dst - odst) * 8;
 	}
 	/* Extend network to cover the actual mask. */
 	while (bits > ((dst - odst) * 8)) {
@@ -169,7 +203,8 @@ inet_net_pton_ipv4( const char *src, uns
 
 #ifdef INET6
 static int
-getbits(const char *src, int *bitsp) {
+getbits(const char *src, int *bitsp)
+{
 	static const char digits[] = "0123456789";
 	int n;
 	int val;
@@ -185,7 +220,7 @@ getbits(const char *src, int *bitsp) {
 			if (n++ != 0 && val == 0)	

CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
Module Name:othersrc
Committed By:   lukem
Date:   Fri Sep 22 22:48:31 UTC 2023

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

Log Message:
sync tools/compat/fgetln.c 1.12

Switch to a version that does not suffer from reporting the wrong length
if the file contains NULs. From OpenBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 othersrc/libexec/tnftpd/libnetbsd/fgetln.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/fgetln.c
diff -u othersrc/libexec/tnftpd/libnetbsd/fgetln.c:1.6 othersrc/libexec/tnftpd/libnetbsd/fgetln.c:1.7
--- othersrc/libexec/tnftpd/libnetbsd/fgetln.c:1.6	Sun Sep 21 16:35:25 2008
+++ othersrc/libexec/tnftpd/libnetbsd/fgetln.c	Fri Sep 22 22:48:31 2023
@@ -1,77 +1,101 @@
-/* $NetBSD: fgetln.c,v 1.6 2008/09/21 16:35:25 lukem Exp $ */
+/*	$NetBSD: fgetln.c,v 1.7 2023/09/22 22:48:31 lukem Exp $	*/
 
-/*-
- * Copyright (c) 1998 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Christos Zoulas.
+/* from:	NetBSD: fgetln.c,v 1.12 2015/10/09 14:42:40 christos Exp */
+/* upstream:	tools/compat/fgetln.c */
+
+/*
+ * Copyright (c) 2015 Joerg Jung 
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * portable fgetln() version
  */
 
 #include "tnftpd.h"
 
+#if 0
+#ifdef HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+#endif
+
+#if !HAVE_FGETLN
+
+#if 0
+#include 
+#ifndef HAVE_NBTOOL_CONFIG_H
+/* These headers are required, but included from nbtool_config.h */
+#include 
+#include 
+#include 
+#endif
+#endif
+
 char *
-fgetln(fp, len)
-	FILE *fp;
-	size_t *len;
+fgetln(FILE *fp, size_t *len)
 {
 	static char *buf = NULL;
-	static size_t bufsiz = 0;
-	char *ptr;
-
+	static size_t bufsz = 0;
+	size_t r = 0;
+	char *p;
+	int c, e;
 
-	if (buf == NULL) {
-		bufsiz = BUFSIZ;
-		if ((buf = malloc(bufsiz)) == NULL)
+	if (!fp || !len) {
+		errno = EINVAL;
+		return NULL;
+	}
+	if (!buf) {
+		if (!(buf = calloc(1, BUFSIZ)))
 			return NULL;
+		bufsz = BUFSIZ;
 	}
+	while ((c = getc(fp)) != EOF) {
+		buf[r++] = c;
+		if (r == bufsz) {
+			/*
+			 * Original uses reallocarray() but we don't have it
+			 * in tools.
+			 */
+			if (!(p = realloc(buf, 2 * bufsz))) {
+e = errno;
+free(buf);
+errno = e;
+buf = NULL, bufsz = 0;
+return NULL;
+			}
+			buf = p, bufsz = 2 * bufsz;
+		}
+		if (c == '\n')
+			break;
+	}
+	return (*len = r) ? buf : NULL;
+}
+#endif
 
-	if (fgets(buf, bufsiz, fp) == NULL)
-		return NULL;
-
-	*len = 0;
-	while ((ptr = strchr([*len], '\n')) == NULL) {
-		size_t nbufsiz = bufsiz + BUFSIZ;
-		char *nbuf = realloc(buf, nbufsiz);
-
-		if (nbuf == NULL) {
-			int oerrno = errno;
-			free(buf);
-			errno = oerrno;
-			buf = NULL;
-			return NULL;
-		} else
-			buf = nbuf;
 
-		*len = bufsiz;
-		if (fgets([bufsiz], 

CVS commit: othersrc/libexec/tnftpd/libnetbsd

2023-09-22 Thread Luke Mewburn
Module Name:othersrc
Committed By:   lukem
Date:   Fri Sep 22 22:48:31 UTC 2023

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

Log Message:
sync tools/compat/fgetln.c 1.12

Switch to a version that does not suffer from reporting the wrong length
if the file contains NULs. From OpenBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 othersrc/libexec/tnftpd/libnetbsd/fgetln.c

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



Re: CVS commit: othersrc/libexec/tnftpd/libnetbsd

2019-01-23 Thread Luke Mewburn
On 19-01-24 03:34, Christos Zoulas wrote:
  | In article <20190124025248.b6e8bf...@cvs.netbsd.org>,
  | Luke Mewburn  wrote:
  | >-=-=-=-=-=-
  | >
  | >Module Name:   othersrc
  | >Committed By:  lukem
  | >Date:  Thu Jan 24 02:52:48 UTC 2019
  | >
  | >Modified Files:
  | >   othersrc/libexec/tnftpd/libnetbsd: ftpfts.h fts_open.c
  | >
  | >Log Message:
  | >sync to fts.c 1.49, fts.h 1.19
  | >
  | >Update from NetBSD src/lib/libc/gen/fts.c 1.38 to 1.49.
  | >Update from NetBSD src/include/fts.h 1.18 to 1.19.
  | >
  | >Notable changes:
  | >- Minimize changes from upstream NetBSD methods.
  | >- Bump fts_level from short to int to avoid a potential DoS.
  | >- Make sure fts_statp is NULL when FTS_NOSTAT is set.
  | >- Use [non-standard] O_CLOEXEC instead of fcntl(FD_CLOEXEC).
  | 
  | Non-standard, how so?
  | http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
  
Good to know. Thanks.


Re: CVS commit: othersrc/libexec/tnftpd/libnetbsd

2019-01-23 Thread Christos Zoulas
In article <20190124025248.b6e8bf...@cvs.netbsd.org>,
Luke Mewburn  wrote:
>-=-=-=-=-=-
>
>Module Name:   othersrc
>Committed By:  lukem
>Date:  Thu Jan 24 02:52:48 UTC 2019
>
>Modified Files:
>   othersrc/libexec/tnftpd/libnetbsd: ftpfts.h fts_open.c
>
>Log Message:
>sync to fts.c 1.49, fts.h 1.19
>
>Update from NetBSD src/lib/libc/gen/fts.c 1.38 to 1.49.
>Update from NetBSD src/include/fts.h 1.18 to 1.19.
>
>Notable changes:
>- Minimize changes from upstream NetBSD methods.
>- Bump fts_level from short to int to avoid a potential DoS.
>- Make sure fts_statp is NULL when FTS_NOSTAT is set.
>- Use [non-standard] O_CLOEXEC instead of fcntl(FD_CLOEXEC).

Non-standard, how so?
http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html

christos