CVS commit: src/lib/libwrap

2021-03-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 18 01:49:09 UTC 2021

Modified Files:
src/lib/libwrap: hosts_access.c

Log Message:
simplify expression, daemon is an array can't be NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libwrap/hosts_access.c

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

Modified files:

Index: src/lib/libwrap/hosts_access.c
diff -u src/lib/libwrap/hosts_access.c:1.23 src/lib/libwrap/hosts_access.c:1.24
--- src/lib/libwrap/hosts_access.c:1.23	Sun Mar  7 10:09:12 2021
+++ src/lib/libwrap/hosts_access.c	Wed Mar 17 21:49:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: hosts_access.c,v 1.23 2021/03/07 15:09:12 christos Exp $	*/
+/*	$NetBSD: hosts_access.c,v 1.24 2021/03/18 01:49:09 christos Exp $	*/
 
  /*
   * This module implements a simple access control language that is based on
@@ -24,7 +24,7 @@
 #if 0
 static char sccsid[] = "@(#) hosts_access.c 1.21 97/02/12 02:13:22";
 #else
-__RCSID("$NetBSD: hosts_access.c,v 1.23 2021/03/07 15:09:12 christos Exp $");
+__RCSID("$NetBSD: hosts_access.c,v 1.24 2021/03/18 01:49:09 christos Exp $");
 #endif
 #endif
 
@@ -108,17 +108,16 @@ static void
 pfilter_notify(struct request_info *request, int b)
 {
 static struct blocklist *blstate;
+int fd = request->fd != -1 ? request->fd : 3;
 
 if (blstate == NULL) {
 	blstate = blocklist_open();
 }
 if (request->client->sin != NULL) {
-	blocklist_sa_r(blstate, b, request->fd != -1 ? request->fd : 3,
-		request->client->sin, request->client->sin->sa_len,
-		request->daemon ? request->daemon : getprogname());
+	blocklist_sa_r(blstate, b, fd, request->client->sin,
+		request->client->sin->sa_len, request->daemon);
 } else {
-	blocklist_r(blstate, b, (request->fd != -1) ? request->fd : 3,
-		request->daemon ? request->daemon : getprogname());
+	blocklist_r(blstate, b, fd, request->daemon);
 }
 }
 



CVS commit: src/lib/libwrap

2021-03-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 18 01:49:09 UTC 2021

Modified Files:
src/lib/libwrap: hosts_access.c

Log Message:
simplify expression, daemon is an array can't be NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libwrap/hosts_access.c

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



CVS commit: src/lib/libwrap

2021-03-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 13 16:46:49 UTC 2021

Modified Files:
src/lib/libwrap: Makefile

Log Message:
record the libblocklist dependency


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libwrap/Makefile

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



CVS commit: src/lib/libwrap

2021-03-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar 13 16:46:49 UTC 2021

Modified Files:
src/lib/libwrap: Makefile

Log Message:
record the libblocklist dependency


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libwrap/Makefile

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

Modified files:

Index: src/lib/libwrap/Makefile
diff -u src/lib/libwrap/Makefile:1.13 src/lib/libwrap/Makefile:1.14
--- src/lib/libwrap/Makefile:1.13	Sun Mar  7 15:54:41 2021
+++ src/lib/libwrap/Makefile	Sat Mar 13 11:46:49 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.13 2021/03/07 20:54:41 christos Exp $
+#	$NetBSD: Makefile,v 1.14 2021/03/13 16:46:49 christos Exp $
 
 USE_FORT?= yes	# network server
 
@@ -14,8 +14,8 @@ MLINKS+=hosts_access.3 hosts_ctl.3
 MLINKS+=hosts_access.3 request_init.3
 MLINKS+=hosts_access.3 request_set.3
 
-#LDADD+=-lblocklist
-#DPADD+=${LIBBLOCKLIST}
+LDADD+=-lblocklist
+DPADD+=${LIBBLOCKLIST}
 
 INCS= tcpd.h
 INCSDIR=/usr/include



CVS commit: src/lib/libwrap

2021-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  7 20:54:42 UTC 2021

Modified Files:
src/lib/libwrap: Makefile

Log Message:
fix missing chars


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libwrap/Makefile

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

Modified files:

Index: src/lib/libwrap/Makefile
diff -u src/lib/libwrap/Makefile:1.12 src/lib/libwrap/Makefile:1.13
--- src/lib/libwrap/Makefile:1.12	Sun Mar  7 10:09:12 2021
+++ src/lib/libwrap/Makefile	Sun Mar  7 15:54:41 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.12 2021/03/07 15:09:12 christos Exp $
+#	$NetBSD: Makefile,v 1.13 2021/03/07 20:54:41 christos Exp $
 
 USE_FORT?= yes	# network server
 
@@ -15,7 +15,7 @@ MLINKS+=hosts_access.3 request_init.3
 MLINKS+=hosts_access.3 request_set.3
 
 #LDADD+=-lblocklist
-PADD+=${LIBBLOCKLIST}
+#DPADD+=${LIBBLOCKLIST}
 
 INCS= tcpd.h
 INCSDIR=/usr/include



CVS commit: src/lib/libwrap

2021-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Mar  7 20:54:42 UTC 2021

Modified Files:
src/lib/libwrap: Makefile

Log Message:
fix missing chars


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libwrap/Makefile

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



CVS commit: src/lib/libwrap

2020-03-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Mar 30 08:34:38 UTC 2020

Modified Files:
src/lib/libwrap: hosts_access.c

Log Message:
PR/54992: fix hosts_access(5) to works for IPv6 linklocal address without 
scope-id


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libwrap/hosts_access.c

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



CVS commit: src/lib/libwrap

2020-03-30 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Mon Mar 30 08:34:38 UTC 2020

Modified Files:
src/lib/libwrap: hosts_access.c

Log Message:
PR/54992: fix hosts_access(5) to works for IPv6 linklocal address without 
scope-id


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libwrap/hosts_access.c

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

Modified files:

Index: src/lib/libwrap/hosts_access.c
diff -u src/lib/libwrap/hosts_access.c:1.21 src/lib/libwrap/hosts_access.c:1.22
--- src/lib/libwrap/hosts_access.c:1.21	Wed Feb 17 19:52:20 2016
+++ src/lib/libwrap/hosts_access.c	Mon Mar 30 08:34:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: hosts_access.c,v 1.21 2016/02/17 19:52:20 christos Exp $	*/
+/*	$NetBSD: hosts_access.c,v 1.22 2020/03/30 08:34:38 ryo Exp $	*/
 
  /*
   * This module implements a simple access control language that is based on
@@ -24,7 +24,7 @@
 #if 0
 static char sccsid[] = "@(#) hosts_access.c 1.21 97/02/12 02:13:22";
 #else
-__RCSID("$NetBSD: hosts_access.c,v 1.21 2016/02/17 19:52:20 christos Exp $");
+__RCSID("$NetBSD: hosts_access.c,v 1.22 2020/03/30 08:34:38 ryo Exp $");
 #endif
 #endif
 
@@ -561,7 +561,7 @@ masked_match6(char *net_tok, char *mask_
 for (i = 0; i < alen; i++)
 	ap[i] &= mp[i];
 
-if (addr.sa.sa_family == AF_INET6 && addr.sin6.sin6_scope_id &&
+if (addr.sa.sa_family == AF_INET6 && net.sin6.sin6_scope_id &&
 addr.sin6.sin6_scope_id != net.sin6.sin6_scope_id)
 	return NO;
 return (memcmp(ap, np, alen) == 0);



CVS commit: src/lib/libwrap

2019-01-24 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Jan 24 22:07:14 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
remove the new check for tlen >= PTRDIFF_MAX.  the prior
checks assure the condition is met and GCC7 is happy.

suggested by kre.


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

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



CVS commit: src/lib/libwrap

2019-01-24 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Jan 24 22:07:14 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
remove the new check for tlen >= PTRDIFF_MAX.  the prior
checks assure the condition is met and GCC7 is happy.

suggested by kre.


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

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.11 src/lib/libwrap/expandm.c:1.12
--- src/lib/libwrap/expandm.c:1.11	Wed Jan 23 02:48:48 2019
+++ src/lib/libwrap/expandm.c	Thu Jan 24 22:07:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.11 2019/01/23 02:48:48 kre Exp $	*/
+/*	$NetBSD: expandm.c,v 1.12 2019/01/24 22:07:14 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.11 2019/01/23 02:48:48 kre Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.12 2019/01/24 22:07:14 mrg Exp $");
 
 #include 
 #include 
@@ -82,13 +82,6 @@ expandm(const char *fmt, const char *sf,
 
 			tlen = nlen + blen;
 
-			/*
-			 * We can't exceed PTRDIFF_MAX because we would
-			 * not be able to address the pointers
-			 */
-			if (tlen >= PTRDIFF_MAX)
-goto out;
-
 			nbuf = realloc(buf, tlen + 1);
 			if (nbuf == NULL)
 goto out;



CVS commit: src/lib/libwrap

2019-01-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jan 23 02:48:48 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
And as long as we're attempting to achieve perfection in code
that is never going to be executed, let's also check for possible
overflow in a sum that will never be computed...


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libwrap/expandm.c

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



CVS commit: src/lib/libwrap

2019-01-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jan 23 02:48:48 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
And as long as we're attempting to achieve perfection in code
that is never going to be executed, let's also check for possible
overflow in a sum that will never be computed...


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libwrap/expandm.c

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.10 src/lib/libwrap/expandm.c:1.11
--- src/lib/libwrap/expandm.c:1.10	Wed Jan 23 02:32:06 2019
+++ src/lib/libwrap/expandm.c	Wed Jan 23 02:48:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.10 2019/01/23 02:32:06 kre Exp $	*/
+/*	$NetBSD: expandm.c,v 1.11 2019/01/23 02:48:48 kre Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.10 2019/01/23 02:32:06 kre Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.11 2019/01/23 02:48:48 kre Exp $");
 
 #include 
 #include 
@@ -68,7 +68,19 @@ expandm(const char *fmt, const char *sf,
 		 */
 		if (__predict_false(nlen >= INT_MAX)) {
 			size_t blen = buf ? strlen(buf) : 0;
-			size_t tlen = nlen + blen;
+			size_t tlen;
+
+			/*
+			 * if we would overflow a ptrdiff_t when computing
+			 * tlen, then don't bother.  The format string is
+			 * simply too large to be converted.
+			 */
+			if (blen >= PTRDIFF_MAX ||
+			nlen >= PTRDIFF_MAX - blen ||
+			nlen >= SIZE_T_MAX - blen)
+goto out;
+
+			tlen = nlen + blen;
 
 			/*
 			 * We can't exceed PTRDIFF_MAX because we would



CVS commit: src/lib/libwrap

2019-01-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jan 23 02:32:06 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
There's no point setting errno, it is just overwritten by err
in the exit path ... this function never fails, it simply sometimes
doesn't actually expand the %m and just leaves the format string
intact.

And declare variables at the head of their scope, not at some random
place in the middle of the code, whatever C allows, that is just ugly.


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

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.9 src/lib/libwrap/expandm.c:1.10
--- src/lib/libwrap/expandm.c:1.9	Wed Jan 23 02:00:00 2019
+++ src/lib/libwrap/expandm.c	Wed Jan 23 02:32:06 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.9 2019/01/23 02:00:00 christos Exp $	*/
+/*	$NetBSD: expandm.c,v 1.10 2019/01/23 02:32:06 kre Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.9 2019/01/23 02:00:00 christos Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.10 2019/01/23 02:32:06 kre Exp $");
 
 #include 
 #include 
@@ -56,11 +56,12 @@ expandm(const char *fmt, const char *sf,
 	buf = NULL;
 	for (ptr = fmt; (m = strstr(ptr, "%m")) != NULL; ptr = m + 2) {
 		size_t cnt = 0;
+		size_t nlen;
 
 		for (char *p = m; p >= ptr && *p == '%'; p--)
 			cnt++;
 
-		size_t nlen = (size_t)(m - ptr);
+		nlen = (size_t)(m - ptr);
 		/*
 		 * we can't exceed INT_MAX because int is used as 
 		 * a format width
@@ -73,10 +74,8 @@ expandm(const char *fmt, const char *sf,
 			 * We can't exceed PTRDIFF_MAX because we would
 			 * not be able to address the pointers
 			 */
-			if (tlen >= PTRDIFF_MAX) {
-errno = EINVAL;
+			if (tlen >= PTRDIFF_MAX)
 goto out;
-			}
 
 			nbuf = realloc(buf, tlen + 1);
 			if (nbuf == NULL)



CVS commit: src/lib/libwrap

2019-01-22 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Jan 23 02:32:06 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
There's no point setting errno, it is just overwritten by err
in the exit path ... this function never fails, it simply sometimes
doesn't actually expand the %m and just leaves the format string
intact.

And declare variables at the head of their scope, not at some random
place in the middle of the code, whatever C allows, that is just ugly.


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

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



CVS commit: src/lib/libwrap

2019-01-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 23 02:00:00 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
limit allocation to PTRDIFF_T to appease gcc-7, from mrg@


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libwrap/expandm.c

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



CVS commit: src/lib/libwrap

2019-01-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 23 02:00:00 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
limit allocation to PTRDIFF_T to appease gcc-7, from mrg@


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libwrap/expandm.c

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.8 src/lib/libwrap/expandm.c:1.9
--- src/lib/libwrap/expandm.c:1.8	Sun Jan 13 22:30:25 2019
+++ src/lib/libwrap/expandm.c	Tue Jan 22 21:00:00 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.8 2019/01/14 03:30:25 kre Exp $	*/
+/*	$NetBSD: expandm.c,v 1.9 2019/01/23 02:00:00 christos Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.8 2019/01/14 03:30:25 kre Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.9 2019/01/23 02:00:00 christos Exp $");
 
 #include 
 #include 
@@ -60,16 +60,30 @@ expandm(const char *fmt, const char *sf,
 		for (char *p = m; p >= ptr && *p == '%'; p--)
 			cnt++;
 
-		if (__predict_false((m - ptr) >= INT_MAX)) {
+		size_t nlen = (size_t)(m - ptr);
+		/*
+		 * we can't exceed INT_MAX because int is used as 
+		 * a format width
+		 */
+		if (__predict_false(nlen >= INT_MAX)) {
 			size_t blen = buf ? strlen(buf) : 0;
-			size_t nlen = (size_t)(m - ptr);
+			size_t tlen = nlen + blen;
 
-			nbuf = realloc(buf, blen + nlen + 1);
+			/*
+			 * We can't exceed PTRDIFF_MAX because we would
+			 * not be able to address the pointers
+			 */
+			if (tlen >= PTRDIFF_MAX) {
+errno = EINVAL;
+goto out;
+			}
+
+			nbuf = realloc(buf, tlen + 1);
 			if (nbuf == NULL)
 goto out;
 
 			memcpy(nbuf + blen, ptr, nlen);
-			nbuf[blen + nlen] = '\0';
+			nbuf[tlen] = '\0';
 			ptr += nlen;
 			buf = nbuf;
 		}



CVS commit: src/lib/libwrap

2019-01-13 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Jan 14 03:30:25 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
Whitespace (indent with tabs, rather than spaces), and rearrange one
line that needed wrapping so it no longer does, and is (IMO) clearer.
WHile here, note that this was created in 2019, not 2018, for the
copyright notice...

NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libwrap/expandm.c

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.7 src/lib/libwrap/expandm.c:1.8
--- src/lib/libwrap/expandm.c:1.7	Sun Jan 13 06:10:34 2019
+++ src/lib/libwrap/expandm.c	Mon Jan 14 03:30:25 2019
@@ -1,7 +1,7 @@
-/*	$NetBSD: expandm.c,v 1.7 2019/01/13 06:10:34 kre Exp $	*/
+/*	$NetBSD: expandm.c,v 1.8 2019/01/14 03:30:25 kre Exp $	*/
 
 /*-
- * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.7 2019/01/13 06:10:34 kre Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.8 2019/01/14 03:30:25 kre Exp $");
 
 #include 
 #include 
@@ -53,27 +53,26 @@ expandm(const char *fmt, const char *sf,
 	char *buf, *m, *nbuf;
 	const char *ptr;
 
-	for (ptr = fmt, buf = NULL; (m = strstr(ptr, "%m")) != NULL;
-	ptr = m + 2)
-	{
+	buf = NULL;
+	for (ptr = fmt; (m = strstr(ptr, "%m")) != NULL; ptr = m + 2) {
 		size_t cnt = 0;
 
 		for (char *p = m; p >= ptr && *p == '%'; p--)
 			cnt++;
 
-   if (__predict_false((m - ptr) >= INT_MAX)) {
-size_t blen = buf ? strlen(buf) : 0;
-size_t nlen = (size_t)(m - ptr);
-
-nbuf = realloc(buf, blen + nlen + 1);
-if (nbuf == NULL)
-goto out;
-
-memcpy(nbuf + blen, ptr, nlen);
-nbuf[blen + nlen] = '\0';
-ptr += nlen;
-buf = nbuf;
-}
+		if (__predict_false((m - ptr) >= INT_MAX)) {
+			size_t blen = buf ? strlen(buf) : 0;
+			size_t nlen = (size_t)(m - ptr);
+
+			nbuf = realloc(buf, blen + nlen + 1);
+			if (nbuf == NULL)
+goto out;
+
+			memcpy(nbuf + blen, ptr, nlen);
+			nbuf[blen + nlen] = '\0';
+			ptr += nlen;
+			buf = nbuf;
+		}
 
 		if (__predict_true(e == NULL && (cnt & 1) != 0))
 			e = strerror(err);



CVS commit: src/lib/libwrap

2019-01-13 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Jan 14 03:30:25 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
Whitespace (indent with tabs, rather than spaces), and rearrange one
line that needed wrapping so it no longer does, and is (IMO) clearer.
WHile here, note that this was created in 2019, not 2018, for the
copyright notice...

NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libwrap/expandm.c

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



CVS commit: src/lib/libwrap

2019-01-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Jan 13 06:10:34 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
Always return from expandm() with errno unaltered, so on the
off chance it failed, there's still the possibility that whatever
processes the result will be able to deal with the %m that would
(presumably) be left in the format string.

And as a frill, don't call strerror() until we know we are
going to use its result (still call it only once, no matter
how many %m's are in the format string).


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libwrap/expandm.c

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.6 src/lib/libwrap/expandm.c:1.7
--- src/lib/libwrap/expandm.c:1.6	Sun Jan 13 01:32:51 2019
+++ src/lib/libwrap/expandm.c	Sun Jan 13 06:10:34 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.6 2019/01/13 01:32:51 christos Exp $	*/
+/*	$NetBSD: expandm.c,v 1.7 2019/01/13 06:10:34 kre Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.6 2019/01/13 01:32:51 christos Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.7 2019/01/13 06:10:34 kre Exp $");
 
 #include 
 #include 
@@ -48,7 +48,8 @@ __RCSID("$NetBSD: expandm.c,v 1.6 2019/0
 const char * __attribute__((__format_arg__(1)))
 expandm(const char *fmt, const char *sf, char **rbuf)
 {
-	const char *e = strerror(errno);
+	const int err = errno;
+	const char *e = NULL;
 	char *buf, *m, *nbuf;
 	const char *ptr;
 
@@ -74,6 +75,8 @@ expandm(const char *fmt, const char *sf,
 buf = nbuf;
 }
 
+		if (__predict_true(e == NULL && (cnt & 1) != 0))
+			e = strerror(err);
 		if (asprintf(, "%s%.*s%s", buf ? buf : "",
 		(int)(m - ptr), ptr, (cnt & 1) ? e : "%m") == -1)
 			goto out;
@@ -87,11 +90,13 @@ expandm(const char *fmt, const char *sf,
 	free(buf);
 	if (rbuf)
 		*rbuf = nbuf;
+	errno = err;
 	return nbuf;
 out:
 	free(buf);
 	if (rbuf)
 		*rbuf = NULL;
+	errno = err;
 	return fmt;
 }
 



CVS commit: src/lib/libwrap

2019-01-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Jan 13 06:10:34 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
Always return from expandm() with errno unaltered, so on the
off chance it failed, there's still the possibility that whatever
processes the result will be able to deal with the %m that would
(presumably) be left in the format string.

And as a frill, don't call strerror() until we know we are
going to use its result (still call it only once, no matter
how many %m's are in the format string).


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libwrap/expandm.c

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



CVS commit: src/lib/libwrap

2019-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 13 01:32:51 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
check for *. integer overflow over ptrdiff. Pointed out by kre@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libwrap/expandm.c

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



CVS commit: src/lib/libwrap

2019-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jan 13 01:32:51 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
check for *. integer overflow over ptrdiff. Pointed out by kre@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libwrap/expandm.c

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.5 src/lib/libwrap/expandm.c:1.6
--- src/lib/libwrap/expandm.c:1.5	Sat Jan 12 17:14:08 2019
+++ src/lib/libwrap/expandm.c	Sat Jan 12 20:32:51 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.5 2019/01/12 22:14:08 kre Exp $	*/
+/*	$NetBSD: expandm.c,v 1.6 2019/01/13 01:32:51 christos Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,8 +29,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.5 2019/01/12 22:14:08 kre Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.6 2019/01/13 01:32:51 christos Exp $");
 
+#include 
 #include 
 #include 
 #include 
@@ -38,6 +39,12 @@ __RCSID("$NetBSD: expandm.c,v 1.5 2019/0
 
 #include "expandm.h"
 
+#ifdef TEST
+#undef INT_MAX
+#define INT_MAX 31
+#endif
+
+
 const char * __attribute__((__format_arg__(1)))
 expandm(const char *fmt, const char *sf, char **rbuf)
 {
@@ -49,8 +56,24 @@ expandm(const char *fmt, const char *sf,
 	ptr = m + 2)
 	{
 		size_t cnt = 0;
+
 		for (char *p = m; p >= ptr && *p == '%'; p--)
 			cnt++;
+
+   if (__predict_false((m - ptr) >= INT_MAX)) {
+size_t blen = buf ? strlen(buf) : 0;
+size_t nlen = (size_t)(m - ptr);
+
+nbuf = realloc(buf, blen + nlen + 1);
+if (nbuf == NULL)
+goto out;
+
+memcpy(nbuf + blen, ptr, nlen);
+nbuf[blen + nlen] = '\0';
+ptr += nlen;
+buf = nbuf;
+}
+
 		if (asprintf(, "%s%.*s%s", buf ? buf : "",
 		(int)(m - ptr), ptr, (cnt & 1) ? e : "%m") == -1)
 			goto out;



CVS commit: src/lib/libwrap

2019-01-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jan 12 22:14:08 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c expandm.h

Log Message:
Make expandm() return a const char * so we can do away with __UNCONST()
and more importantly, so that we don't accidentally return a value
that is a const char * in reality (pointer to read only string) as a
char *.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libwrap/expandm.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libwrap/expandm.h

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.4 src/lib/libwrap/expandm.c:1.5
--- src/lib/libwrap/expandm.c:1.4	Sat Jan 12 21:50:29 2019
+++ src/lib/libwrap/expandm.c	Sat Jan 12 22:14:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.4 2019/01/12 21:50:29 christos Exp $	*/
+/*	$NetBSD: expandm.c,v 1.5 2019/01/12 22:14:08 kre Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.4 2019/01/12 21:50:29 christos Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.5 2019/01/12 22:14:08 kre Exp $");
 
 #include 
 #include 
@@ -38,7 +38,7 @@ __RCSID("$NetBSD: expandm.c,v 1.4 2019/0
 
 #include "expandm.h"
 
-char * __attribute__((__format_arg__(1)))
+const char * __attribute__((__format_arg__(1)))
 expandm(const char *fmt, const char *sf, char **rbuf)
 {
 	const char *e = strerror(errno);
@@ -69,7 +69,7 @@ out:
 	free(buf);
 	if (rbuf)
 		*rbuf = NULL;
-	return __UNCONST(fmt);
+	return fmt;
 }
 
 #ifdef TEST
@@ -77,10 +77,8 @@ int
 main(int argc, char *argv[])
 {
 	errno = ERANGE;
-	printf(argv[1]);
-	printf("\n");
-	printf(expandm(argv[1], "\n", NULL));
-	printf("%s\n", expandm(argv[1], NULL, NULL));
+	printf("%s\n", expandm(argc > 1 ? argv[1] : "Message %%m=%m: %%%m%%",
+	"...", NULL));
 	return 0;
 }
 #endif

Index: src/lib/libwrap/expandm.h
diff -u src/lib/libwrap/expandm.h:1.2 src/lib/libwrap/expandm.h:1.3
--- src/lib/libwrap/expandm.h:1.2	Sat Jan 12 19:08:24 2019
+++ src/lib/libwrap/expandm.h	Sat Jan 12 22:14:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.h,v 1.2 2019/01/12 19:08:24 christos Exp $	*/
+/*	$NetBSD: expandm.h,v 1.3 2019/01/12 22:14:08 kre Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -31,6 +31,6 @@
 #include 
 
 __BEGIN_DECLS
-char * __attribute__((__format_arg__(1))) expandm(const char *, const char *,
-char **);
+const char * __attribute__((__format_arg__(1))) expandm(const char *,
+const char *, char **);
 __END_DECLS



CVS commit: src/lib/libwrap

2019-01-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jan 12 22:14:08 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c expandm.h

Log Message:
Make expandm() return a const char * so we can do away with __UNCONST()
and more importantly, so that we don't accidentally return a value
that is a const char * in reality (pointer to read only string) as a
char *.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libwrap/expandm.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libwrap/expandm.h

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



CVS commit: src/lib/libwrap

2019-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 12 21:50:29 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
Don't do %%m -> %%%m escaping, requested by gson@.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libwrap/expandm.c

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.3 src/lib/libwrap/expandm.c:1.4
--- src/lib/libwrap/expandm.c:1.3	Sat Jan 12 16:05:37 2019
+++ src/lib/libwrap/expandm.c	Sat Jan 12 16:50:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.3 2019/01/12 21:05:37 kre Exp $	*/
+/*	$NetBSD: expandm.c,v 1.4 2019/01/12 21:50:29 christos Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.3 2019/01/12 21:05:37 kre Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.4 2019/01/12 21:50:29 christos Exp $");
 
 #include 
 #include 
@@ -52,7 +52,7 @@ expandm(const char *fmt, const char *sf,
 		for (char *p = m; p >= ptr && *p == '%'; p--)
 			cnt++;
 		if (asprintf(, "%s%.*s%s", buf ? buf : "",
-		(int)(m - ptr), ptr, (cnt & 1) ? e : "%%m") == -1)
+		(int)(m - ptr), ptr, (cnt & 1) ? e : "%m") == -1)
 			goto out;
 		free(buf);
 		buf = nbuf;
@@ -77,7 +77,10 @@ int
 main(int argc, char *argv[])
 {
 	errno = ERANGE;
-	printf("%s\n", expandm(argv[1], "", NULL));
+	printf(argv[1]);
+	printf("\n");
+	printf(expandm(argv[1], "\n", NULL));
+	printf("%s\n", expandm(argv[1], NULL, NULL));
 	return 0;
 }
 #endif



CVS commit: src/lib/libwrap

2019-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 12 21:50:29 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
Don't do %%m -> %%%m escaping, requested by gson@.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libwrap/expandm.c

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



CVS commit: src/lib/libwrap

2019-01-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jan 12 21:05:37 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
Return the buffer that has not been freed, so it can be later,
rather than the one that already was.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libwrap/expandm.c

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

Modified files:

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.2 src/lib/libwrap/expandm.c:1.3
--- src/lib/libwrap/expandm.c:1.2	Sat Jan 12 19:08:24 2019
+++ src/lib/libwrap/expandm.c	Sat Jan 12 21:05:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.2 2019/01/12 19:08:24 christos Exp $	*/
+/*	$NetBSD: expandm.c,v 1.3 2019/01/12 21:05:37 kre Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.2 2019/01/12 19:08:24 christos Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.3 2019/01/12 21:05:37 kre Exp $");
 
 #include 
 #include 
@@ -63,7 +63,7 @@ expandm(const char *fmt, const char *sf,
 
 	free(buf);
 	if (rbuf)
-		*rbuf = buf;
+		*rbuf = nbuf;
 	return nbuf;
 out:
 	free(buf);



CVS commit: src/lib/libwrap

2019-01-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jan 12 21:05:37 UTC 2019

Modified Files:
src/lib/libwrap: expandm.c

Log Message:
Return the buffer that has not been freed, so it can be later,
rather than the one that already was.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libwrap/expandm.c

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



CVS commit: src/lib/libwrap

2019-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 12 19:08:24 UTC 2019

Modified Files:
src/lib/libwrap: diag.c expandm.c expandm.h

Log Message:
Provide an extra argument to store the returned pointer so we can use
the function directly as the return format (before assigning it to a
variable) to appease clang.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libwrap/diag.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libwrap/expandm.c src/lib/libwrap/expandm.h

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



CVS commit: src/lib/libwrap

2019-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 12 19:08:24 UTC 2019

Modified Files:
src/lib/libwrap: diag.c expandm.c expandm.h

Log Message:
Provide an extra argument to store the returned pointer so we can use
the function directly as the return format (before assigning it to a
variable) to appease clang.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libwrap/diag.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libwrap/expandm.c src/lib/libwrap/expandm.h

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

Modified files:

Index: src/lib/libwrap/diag.c
diff -u src/lib/libwrap/diag.c:1.16 src/lib/libwrap/diag.c:1.17
--- src/lib/libwrap/diag.c:1.16	Fri Jan 11 15:37:30 2019
+++ src/lib/libwrap/diag.c	Sat Jan 12 14:08:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: diag.c,v 1.16 2019/01/11 20:37:30 christos Exp $	*/
+/*	$NetBSD: diag.c,v 1.17 2019/01/12 19:08:24 christos Exp $	*/
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
 #else
-__RCSID("$NetBSD: diag.c,v 1.16 2019/01/11 20:37:30 christos Exp $");
+__RCSID("$NetBSD: diag.c,v 1.17 2019/01/12 19:08:24 christos Exp $");
 #endif
 #endif
 
@@ -46,22 +46,21 @@ static void tcpd_diag(int, const char *,
 static void
 tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
 {
-char *buf2, *buf = expandm(fmt, NULL);
+char *buf, *bufx;
 
-if (vasprintf(, buf, ap) == -1)
-	buf2 = buf;
+if (vasprintf(, expandm(fmt, NULL, ), ap) == -1)
+	buf = __UNCONST(fmt);
+free(bufx);
 
 /* contruct the tag for the log entry */
 if (tcpd_context.file)
 	syslog(severity, "%s: %s, line %d: %s",
-	tag, tcpd_context.file, tcpd_context.line, buf2);
+	tag, tcpd_context.file, tcpd_context.line, buf);
 else
-	syslog(severity, "%s: %s", tag, buf2);
+	syslog(severity, "%s: %s", tag, buf);
 
 if (buf != fmt)
-free(buf);
-if (buf2 != buf)
-	free(buf2);
+	free(buf);
 }
 
 /* tcpd_warn - report problem of some sort and proceed */

Index: src/lib/libwrap/expandm.c
diff -u src/lib/libwrap/expandm.c:1.1 src/lib/libwrap/expandm.c:1.2
--- src/lib/libwrap/expandm.c:1.1	Fri Jan 11 15:37:30 2019
+++ src/lib/libwrap/expandm.c	Sat Jan 12 14:08:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.c,v 1.1 2019/01/11 20:37:30 christos Exp $	*/
+/*	$NetBSD: expandm.c,v 1.2 2019/01/12 19:08:24 christos Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: expandm.c,v 1.1 2019/01/11 20:37:30 christos Exp $");
+__RCSID("$NetBSD: expandm.c,v 1.2 2019/01/12 19:08:24 christos Exp $");
 
 #include 
 #include 
@@ -39,13 +39,15 @@ __RCSID("$NetBSD: expandm.c,v 1.1 2019/0
 #include "expandm.h"
 
 char * __attribute__((__format_arg__(1)))
-expandm(const char *fmt, const char *sf)
+expandm(const char *fmt, const char *sf, char **rbuf)
 {
 	const char *e = strerror(errno);
 	char *buf, *m, *nbuf;
 	const char *ptr;
 
-	for (ptr = fmt, buf = NULL; (m = strstr(ptr, "%m")); ptr = m + 2) {
+	for (ptr = fmt, buf = NULL; (m = strstr(ptr, "%m")) != NULL;
+	ptr = m + 2)
+	{
 		size_t cnt = 0;
 		for (char *p = m; p >= ptr && *p == '%'; p--)
 			cnt++;
@@ -60,9 +62,13 @@ expandm(const char *fmt, const char *sf)
 		goto out;
 
 	free(buf);
+	if (rbuf)
+		*rbuf = buf;
 	return nbuf;
 out:
 	free(buf);
+	if (rbuf)
+		*rbuf = NULL;
 	return __UNCONST(fmt);
 }
 
@@ -71,7 +77,7 @@ int
 main(int argc, char *argv[])
 {
 	errno = ERANGE;
-	printf("%s\n", expandm(argv[1]));
+	printf("%s\n", expandm(argv[1], "", NULL));
 	return 0;
 }
 #endif
Index: src/lib/libwrap/expandm.h
diff -u src/lib/libwrap/expandm.h:1.1 src/lib/libwrap/expandm.h:1.2
--- src/lib/libwrap/expandm.h:1.1	Fri Jan 11 15:37:30 2019
+++ src/lib/libwrap/expandm.h	Sat Jan 12 14:08:24 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: expandm.h,v 1.1 2019/01/11 20:37:30 christos Exp $	*/
+/*	$NetBSD: expandm.h,v 1.2 2019/01/12 19:08:24 christos Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -31,5 +31,6 @@
 #include 
 
 __BEGIN_DECLS
-char * __attribute__((__format_arg__(1))) expandm(const char *, const char *);
+char * __attribute__((__format_arg__(1))) expandm(const char *, const char *,
+char **);
 __END_DECLS



CVS commit: src/lib/libwrap

2019-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 11 20:37:30 UTC 2019

Modified Files:
src/lib/libwrap: Makefile diag.c
Added Files:
src/lib/libwrap: expandm.c expandm.h

Log Message:
Use a utility function to expand %m correctly...


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libwrap/Makefile
cvs rdiff -u -r1.15 -r1.16 src/lib/libwrap/diag.c
cvs rdiff -u -r0 -r1.1 src/lib/libwrap/expandm.c src/lib/libwrap/expandm.h

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

Modified files:

Index: src/lib/libwrap/Makefile
diff -u src/lib/libwrap/Makefile:1.10 src/lib/libwrap/Makefile:1.11
--- src/lib/libwrap/Makefile:1.10	Mon May 28 08:06:22 2007
+++ src/lib/libwrap/Makefile	Fri Jan 11 15:37:30 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.10 2007/05/28 12:06:22 tls Exp $
+#	$NetBSD: Makefile,v 1.11 2019/01/11 20:37:30 christos Exp $
 
 USE_FORT?= yes	# network server
 
@@ -6,7 +6,7 @@ LIB=	wrap
 
 SRCS=	hosts_access.c options.c shell_cmd.c rfc931.c eval.c hosts_ctl.c \
 	refuse.c percent_x.c clean_exit.c fix_options.c socket.c \
-	update.c misc.c diag.c
+	update.c misc.c diag.c expandm.c
 MAN=	hosts_access.3 hosts_access.5 hosts_options.5
 MLINKS+=hosts_access.5 hosts.allow.5
 MLINKS+=hosts_access.5 hosts.deny.5

Index: src/lib/libwrap/diag.c
diff -u src/lib/libwrap/diag.c:1.15 src/lib/libwrap/diag.c:1.16
--- src/lib/libwrap/diag.c:1.15	Fri Jan 11 11:15:20 2019
+++ src/lib/libwrap/diag.c	Fri Jan 11 15:37:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: diag.c,v 1.15 2019/01/11 16:15:20 christos Exp $	*/
+/*	$NetBSD: diag.c,v 1.16 2019/01/11 20:37:30 christos Exp $	*/
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
 #else
-__RCSID("$NetBSD: diag.c,v 1.15 2019/01/11 16:15:20 christos Exp $");
+__RCSID("$NetBSD: diag.c,v 1.16 2019/01/11 20:37:30 christos Exp $");
 #endif
 #endif
 
@@ -33,6 +33,7 @@ __RCSID("$NetBSD: diag.c,v 1.15 2019/01/
 /* Local stuff */
 
 #include "tcpd.h"
+#include "expandm.h"
 
 struct tcpd_context tcpd_context;
 jmp_buf tcpd_buf;
@@ -45,25 +46,22 @@ static void tcpd_diag(int, const char *,
 static void
 tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
 {
-char *buf;
-int e, oerrno = errno;
+char *buf2, *buf = expandm(fmt, NULL);
+
+if (vasprintf(, buf, ap) == -1)
+	buf2 = buf;
 
 /* contruct the tag for the log entry */
 if (tcpd_context.file)
-	e = asprintf(, "%s: %s, line %d: %s",
-	tag, tcpd_context.file, tcpd_context.line, fmt);
+	syslog(severity, "%s: %s, line %d: %s",
+	tag, tcpd_context.file, tcpd_context.line, buf2);
 else
-	e = asprintf(, "%s: %s", tag, fmt);
-
-if (e == -1)
-	buf = __UNCONST(fmt);
-
-errno = oerrno;
-
-vsyslog(severity, buf, ap);
+	syslog(severity, "%s: %s", tag, buf2);
 
 if (buf != fmt)
 free(buf);
+if (buf2 != buf)
+	free(buf2);
 }
 
 /* tcpd_warn - report problem of some sort and proceed */

Added files:

Index: src/lib/libwrap/expandm.c
diff -u /dev/null src/lib/libwrap/expandm.c:1.1
--- /dev/null	Fri Jan 11 15:37:30 2019
+++ src/lib/libwrap/expandm.c	Fri Jan 11 15:37:30 2019
@@ -0,0 +1,77 @@
+/*	$NetBSD: expandm.c,v 1.1 2019/01/11 20:37:30 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ *
+ * 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.
+ */
+#include 
+__RCSID("$NetBSD: expandm.c,v 1.1 2019/01/11 20:37:30 christos Exp $");
+
+#include 

CVS commit: src/lib/libwrap

2019-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 11 20:37:30 UTC 2019

Modified Files:
src/lib/libwrap: Makefile diag.c
Added Files:
src/lib/libwrap: expandm.c expandm.h

Log Message:
Use a utility function to expand %m correctly...


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libwrap/Makefile
cvs rdiff -u -r1.15 -r1.16 src/lib/libwrap/diag.c
cvs rdiff -u -r0 -r1.1 src/lib/libwrap/expandm.c src/lib/libwrap/expandm.h

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



Re: CVS commit: src/lib/libwrap

2019-01-11 Thread Andreas Gustafsson
Christos,

I think libwrap/diag.c 1.15 will read random memory if either the tag
or tcpd_context.file contains "%s".  It's similar to 1.9 but lacks the
code in 1.9 to escape the percent signs (using fixed-length
buffers...).  Kludgy as it was, 1.13 seems like the least bad version
so far.
-- 
Andreas Gustafsson, g...@netbsd.org


CVS commit: src/lib/libwrap

2019-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 11 16:15:20 UTC 2019

Modified Files:
src/lib/libwrap: diag.c

Log Message:
let's try one more time: prepare the format to pass to syslog instead
of trying to escape %m.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libwrap/diag.c

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



CVS commit: src/lib/libwrap

2019-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 11 16:15:20 UTC 2019

Modified Files:
src/lib/libwrap: diag.c

Log Message:
let's try one more time: prepare the format to pass to syslog instead
of trying to escape %m.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libwrap/diag.c

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

Modified files:

Index: src/lib/libwrap/diag.c
diff -u src/lib/libwrap/diag.c:1.14 src/lib/libwrap/diag.c:1.15
--- src/lib/libwrap/diag.c:1.14	Fri Jan 11 08:05:57 2019
+++ src/lib/libwrap/diag.c	Fri Jan 11 11:15:20 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: diag.c,v 1.14 2019/01/11 13:05:57 christos Exp $	*/
+/*	$NetBSD: diag.c,v 1.15 2019/01/11 16:15:20 christos Exp $	*/
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
 #else
-__RCSID("$NetBSD: diag.c,v 1.14 2019/01/11 13:05:57 christos Exp $");
+__RCSID("$NetBSD: diag.c,v 1.15 2019/01/11 16:15:20 christos Exp $");
 #endif
 #endif
 
@@ -45,33 +45,25 @@ static void tcpd_diag(int, const char *,
 static void
 tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
 {
-char *buf, *buf2, *ptr;
-int oerrno = errno;
-
-if ((ptr = strstr(fmt, "%m")) != NULL) {
-	if (asprintf(, "%.*s%%%s", (int)(ptr - fmt), fmt, ptr) == -1)
-	buf = __UNCONST(fmt);
-} else {
-	buf = __UNCONST(fmt);
-}
+char *buf;
+int e, oerrno = errno;
 
+/* contruct the tag for the log entry */
+if (tcpd_context.file)
+	e = asprintf(, "%s: %s, line %d: %s",
+	tag, tcpd_context.file, tcpd_context.line, fmt);
+else
+	e = asprintf(, "%s: %s", tag, fmt);
 
-if (vasprintf(, buf, ap) == -1)
-	buf2 = buf;
+if (e == -1)
+	buf = __UNCONST(fmt);
 
 errno = oerrno;
 
-/* contruct the tag for the log entry */
-if (tcpd_context.file)
-	syslog(severity, "%s: %s, line %d: %s",
-	tag, tcpd_context.file, tcpd_context.line, buf2);
-else
-	syslog(severity, "%s: %s", tag, buf2);
+vsyslog(severity, buf, ap);
 
 if (buf != fmt)
 free(buf);
-if (buf2 != buf)
-	free(buf2);
 }
 
 /* tcpd_warn - report problem of some sort and proceed */



Re: CVS commit: src/lib/libwrap

2019-01-11 Thread Valery Ushakov
On Fri, Jan 11, 2019 at 07:39:58 +0700, Robert Elz wrote:

> farily easy to add, if only gcc didn't go and do printf format string
> analysis and complain when it sees something it does not understand.

gcc has plugin API that lets you add support for custom format
languages.  We use it at work where we have effectively our own
superset of printf with lots of additional formatters.

-uwe


CVS commit: src/lib/libwrap

2019-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 11 13:05:57 UTC 2019

Modified Files:
src/lib/libwrap: diag.c

Log Message:
instead of handling %m inline, escape it.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libwrap/diag.c

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



CVS commit: src/lib/libwrap

2019-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 11 13:05:57 UTC 2019

Modified Files:
src/lib/libwrap: diag.c

Log Message:
instead of handling %m inline, escape it.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libwrap/diag.c

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

Modified files:

Index: src/lib/libwrap/diag.c
diff -u src/lib/libwrap/diag.c:1.13 src/lib/libwrap/diag.c:1.14
--- src/lib/libwrap/diag.c:1.13	Thu Jan 10 08:53:58 2019
+++ src/lib/libwrap/diag.c	Fri Jan 11 08:05:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: diag.c,v 1.13 2019/01/10 13:53:58 christos Exp $	*/
+/*	$NetBSD: diag.c,v 1.14 2019/01/11 13:05:57 christos Exp $	*/
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
 #else
-__RCSID("$NetBSD: diag.c,v 1.13 2019/01/10 13:53:58 christos Exp $");
+__RCSID("$NetBSD: diag.c,v 1.14 2019/01/11 13:05:57 christos Exp $");
 #endif
 #endif
 
@@ -46,10 +46,10 @@ static void
 tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
 {
 char *buf, *buf2, *ptr;
+int oerrno = errno;
 
 if ((ptr = strstr(fmt, "%m")) != NULL) {
-	if (asprintf(, "%.*s%s%s", (int)(ptr - fmt), fmt, strerror(errno),
-	ptr + 2) == -1)
+	if (asprintf(, "%.*s%%%s", (int)(ptr - fmt), fmt, ptr) == -1)
 	buf = __UNCONST(fmt);
 } else {
 	buf = __UNCONST(fmt);
@@ -59,6 +59,8 @@ tcpd_diag(int severity, const char *tag,
 if (vasprintf(, buf, ap) == -1)
 	buf2 = buf;
 
+errno = oerrno;
+
 /* contruct the tag for the log entry */
 if (tcpd_context.file)
 	syslog(severity, "%s: %s, line %d: %s",



Re: CVS commit: src/lib/libwrap

2019-01-10 Thread Robert Elz
Date:Thu, 10 Jan 2019 20:21:52 -0500
From:chris...@zoulas.com (Christos Zoulas)
Message-ID:  <20190111012152.cc59917f...@rebar.astron.com>

  | I understand, this is why I grepped the source for %m and saw that there
  | was no use other than " %m\0". 

The point was most that libwrap is a public library, and in its tcpd.h
it declares tcpd_warn() as a public function, and notes it as __syslog_like
which means that it handles %m.

Anyone, anywhere (who links against libwrap) can call that function.

That's why I susggested that perhaps what we should do is document
the issue, so that if there is anyone who decides that they need to
include a message that has something like "%d%%mbufs"
that they can expect something quite different than they hoped.
Similarly, if they were even just to use (for some obscure reason)
two %m conversions in one message.

I am not sure where that doc ought be put however, as tcpd_warn
doesn't seem to be documented anywhere (than in tcpd.h).

[This also applies to tcpd_jump() of course, but that one is kind
of hard to imagine anyone wanting to use.]

  | Yes, that is something I wished for many times. But then there are
  | trade-offs (such as compile time checking) and other safety guarantees.

Of course ... perhaps we could make it so that the act of specifying a
new format conversion creates a new printf clone function (which gcc
would then know nothing about ...) which also solves the "lifetime of
the conversion routine" issue (the function which would be provided
to handle the added format would need to exist just as long as the
returned function pointer is kept alive).

Then only calls which need to use the added format would use the
created function, all others would just use the existing ones, with all
the gcc validity checking, and only the others would use the new
one and miss out ... which is certainly no worse than calls which
process the format string, modifying it to insert the data wanted by
the new conversion, then passing the newly constructed format to
printf.

kre



Re: CVS commit: src/lib/libwrap

2019-01-10 Thread Christos Zoulas
On Jan 11,  7:39am, k...@munnari.oz.au (Robert Elz) wrote:
-- Subject: Re: CVS commit: src/lib/libwrap

|   | PR/53851: Andreas Gustafsson: libwrap prints "m" instead of errno
|   | Handle %m inline if needed, otherwise vasprintf strips the %m and...
| 
| That change handles the simple case of %m but fails on %%m (though
| that is, I assume, unlikely, in libwrap error messages).

This is not intended to be a general solution. In fact it is a compromise:
I thought of changing all %m's to %s, strerror(errno) in the messages and
I decided that it was more intrusive than the simplistic change.

| The simple change, making the test be ...
| 
|   if ((ptr = strstr(fmt, "%m")) != NULL &&
|   (ptr == fmt || ptr[-1] != '%'))
| 
| fails on %%%m (though I would guess that is even less likely).
| 
| There's no good way to correctly fix this using this technique, what
| is needed is to do as the syslog() functions do, and actually do a
| (restricted) parse of the format string.

I understand, this is why I grepped the source for %m and saw that there
was no use other than " %m\0". 

| For this though, I suspect it would be overkill.   The point of this message
| is just to make sure everyone is aware of this, and perhaps, if there is
| some suitable place to document it, that that be done.

Yes, the perfect being the enemy of the good.

| Oh for the ability to simply add application specific format specifiers
| to printf - I think plan9 has something along those lines.   It would be
| farily easy to add, if only gcc didn't go and do printf format string
| analysis and complain when it sees something it does not understand.

Yes, that is something I wished for many times. But then there are
trade-offs (such as compile time checking) and other safety guarantees.

christos


Re: CVS commit: src/lib/libwrap

2019-01-10 Thread Robert Elz
Date:Thu, 10 Jan 2019 08:53:27 -0500
From:"Christos Zoulas" 
Message-ID:  <20190110135327.189a1f...@cvs.netbsd.org>

  | PR/53851: Andreas Gustafsson: libwrap prints "m" instead of errno
  | Handle %m inline if needed, otherwise vasprintf strips the %m and...

That change handles the simple case of %m but fails on %%m (though
that is, I assume, unlikely, in libwrap error messages).

The simple change, making the test be ...

if ((ptr = strstr(fmt, "%m")) != NULL &&
(ptr == fmt || ptr[-1] != '%'))

fails on %%%m (though I would guess that is even less likely).

There's no good way to correctly fix this using this technique, what
is needed is to do as the syslog() functions do, and actually do a
(restricted) parse of the format string.

For this though, I suspect it would be overkill.   The point of this message
is just to make sure everyone is aware of this, and perhaps, if there is
some suitable place to document it, that that be done.

Oh for the ability to simply add application specific format specifiers
to printf - I think plan9 has something along those lines.   It would be
farily easy to add, if only gcc didn't go and do printf format string
analysis and complain when it sees something it does not understand.

kre



CVS commit: src/lib/libwrap

2019-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 10 13:53:27 UTC 2019

Modified Files:
src/lib/libwrap: diag.c

Log Message:
PR/53851: Andreas Gustafsson: libwrap prints "m" instead of errno
Handle %m inline if needed, otherwise vasprintf strips the %m and...


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

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

Modified files:

Index: src/lib/libwrap/diag.c
diff -u src/lib/libwrap/diag.c:1.11 src/lib/libwrap/diag.c:1.12
--- src/lib/libwrap/diag.c:1.11	Wed Oct 14 11:54:21 2015
+++ src/lib/libwrap/diag.c	Thu Jan 10 08:53:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: diag.c,v 1.11 2015/10/14 15:54:21 christos Exp $	*/
+/*	$NetBSD: diag.c,v 1.12 2019/01/10 13:53:26 christos Exp $	*/
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
 #else
-__RCSID("$NetBSD: diag.c,v 1.11 2015/10/14 15:54:21 christos Exp $");
+__RCSID("$NetBSD: diag.c,v 1.12 2019/01/10 13:53:26 christos Exp $");
 #endif
 #endif
 
@@ -45,26 +45,33 @@ static void tcpd_diag(int, const char *,
 static void
 tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
 {
-char *buf;
-int oerrno;
+char *buf, *buf2, *ptr;
 
-/* save errno in case we need it */
-oerrno = errno;
-
-if (vasprintf(, fmt, ap) == -1)
+if ((ptr = strstr(fmt, "%m")) != NULL) {
+	if (asprintf(, "%.*s%s%s", (int)(ptr - fmt), fmt, strerror(errno),
+	ptr + 2) == -1)
+	buf = __UNCONST(fmt);
+} else {
 	buf = __UNCONST(fmt);
+}
+
+
+if (vasprintf(, buf, ap) == -1)
+	buf2 = buf;
 
 errno = oerrno;
 
 /* contruct the tag for the log entry */
 if (tcpd_context.file)
 	syslog(severity, "%s: %s, line %d: %s",
-	tag, tcpd_context.file, tcpd_context.line, buf);
+	tag, tcpd_context.file, tcpd_context.line, buf2);
 else
-	syslog(severity, "%s: %s", tag, buf);
+	syslog(severity, "%s: %s", tag, buf2);
 
 if (buf != fmt)
 free(buf);
+if (buf2 != buf)
+	free(buf2);
 }
 
 /* tcpd_warn - report problem of some sort and proceed */



CVS commit: src/lib/libwrap

2019-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 10 13:53:58 UTC 2019

Modified Files:
src/lib/libwrap: diag.c

Log Message:
delete unused variable


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libwrap/diag.c

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

Modified files:

Index: src/lib/libwrap/diag.c
diff -u src/lib/libwrap/diag.c:1.12 src/lib/libwrap/diag.c:1.13
--- src/lib/libwrap/diag.c:1.12	Thu Jan 10 08:53:26 2019
+++ src/lib/libwrap/diag.c	Thu Jan 10 08:53:58 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: diag.c,v 1.12 2019/01/10 13:53:26 christos Exp $	*/
+/*	$NetBSD: diag.c,v 1.13 2019/01/10 13:53:58 christos Exp $	*/
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
 #else
-__RCSID("$NetBSD: diag.c,v 1.12 2019/01/10 13:53:26 christos Exp $");
+__RCSID("$NetBSD: diag.c,v 1.13 2019/01/10 13:53:58 christos Exp $");
 #endif
 #endif
 
@@ -59,8 +59,6 @@ tcpd_diag(int severity, const char *tag,
 if (vasprintf(, buf, ap) == -1)
 	buf2 = buf;
 
-errno = oerrno;
-
 /* contruct the tag for the log entry */
 if (tcpd_context.file)
 	syslog(severity, "%s: %s, line %d: %s",



CVS commit: src/lib/libwrap

2019-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 10 13:53:58 UTC 2019

Modified Files:
src/lib/libwrap: diag.c

Log Message:
delete unused variable


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libwrap/diag.c

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



CVS commit: src/lib/libwrap

2019-01-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 10 13:53:27 UTC 2019

Modified Files:
src/lib/libwrap: diag.c

Log Message:
PR/53851: Andreas Gustafsson: libwrap prints "m" instead of errno
Handle %m inline if needed, otherwise vasprintf strips the %m and...


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

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



CVS commit: src/lib/libwrap

2016-03-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 16 21:38:22 UTC 2016

Modified Files:
src/lib/libwrap: rfc931.c

Log Message:
Avoid setjmp clobbering.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libwrap/rfc931.c

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



CVS commit: src/lib/libwrap

2016-03-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 16 22:32:32 UTC 2016

Modified Files:
src/lib/libwrap: rfc931.c

Log Message:
change static to volatile.


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

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



CVS commit: src/lib/libwrap

2016-03-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 16 21:38:22 UTC 2016

Modified Files:
src/lib/libwrap: rfc931.c

Log Message:
Avoid setjmp clobbering.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libwrap/rfc931.c

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

Modified files:

Index: src/lib/libwrap/rfc931.c
diff -u src/lib/libwrap/rfc931.c:1.10 src/lib/libwrap/rfc931.c:1.11
--- src/lib/libwrap/rfc931.c:1.10	Thu Mar 22 18:59:43 2012
+++ src/lib/libwrap/rfc931.c	Wed Mar 16 17:38:22 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfc931.c,v 1.10 2012/03/22 22:59:43 joerg Exp $	*/
+/*	$NetBSD: rfc931.c,v 1.11 2016/03/16 21:38:22 christos Exp $	*/
 
  /*
   * rfc931() speaks a common subset of the RFC 931, AUTH, TAP, IDENT and RFC
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) rfc931.c 1.10 95/01/02 16:11:34";
 #else
-__RCSID("$NetBSD: rfc931.c,v 1.10 2012/03/22 22:59:43 joerg Exp $");
+__RCSID("$NetBSD: rfc931.c,v 1.11 2016/03/16 21:38:22 christos Exp $");
 #endif
 #endif
 
@@ -87,7 +87,7 @@ rfc931(struct sockaddr *rmt_sin, struct 
 charuser[256];			/* XXX */
 charbuffer[512];		/* XXX */
 char   *cp;
-char   *result = unknown;
+static char   *result = unknown;
 FILE   *fp;
 volatile int salen;
 u_short * volatile rmt_portp;
@@ -95,7 +95,7 @@ rfc931(struct sockaddr *rmt_sin, struct 
 
 /* address family must be the same */
 if (rmt_sin->sa_family != our_sin->sa_family) {
-	strlcpy(dest, result, STRING_LENGTH);
+	strlcpy(dest, unknown, STRING_LENGTH);
 	return;
 }
 switch (rmt_sin->sa_family) {
@@ -110,7 +110,7 @@ rfc931(struct sockaddr *rmt_sin, struct 
 	break;
 #endif
 default:
-	strlcpy(dest, result, STRING_LENGTH);
+	strlcpy(dest, unknown, STRING_LENGTH);
 	return;
 }
 switch (our_sin->sa_family) {
@@ -123,15 +123,10 @@ rfc931(struct sockaddr *rmt_sin, struct 
 	break;
 #endif
 default:
-	strlcpy(dest, result, STRING_LENGTH);
+	strlcpy(dest, unknown, STRING_LENGTH);
 	return;
 }
 
-#ifdef __GNUC__
-(void) /* Avoid longjmp clobbering */
-(void)	/* XXX gcc */
-#endif
-
 /*
  * Use one unbuffered stdio stream for writing to and for reading from
  * the RFC931 etc. server. This is done because of a bug in the SunOS



CVS commit: src/lib/libwrap

2016-03-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 16 22:32:32 UTC 2016

Modified Files:
src/lib/libwrap: rfc931.c

Log Message:
change static to volatile.


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

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

Modified files:

Index: src/lib/libwrap/rfc931.c
diff -u src/lib/libwrap/rfc931.c:1.11 src/lib/libwrap/rfc931.c:1.12
--- src/lib/libwrap/rfc931.c:1.11	Wed Mar 16 17:38:22 2016
+++ src/lib/libwrap/rfc931.c	Wed Mar 16 18:32:32 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfc931.c,v 1.11 2016/03/16 21:38:22 christos Exp $	*/
+/*	$NetBSD: rfc931.c,v 1.12 2016/03/16 22:32:32 christos Exp $	*/
 
  /*
   * rfc931() speaks a common subset of the RFC 931, AUTH, TAP, IDENT and RFC
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) rfc931.c 1.10 95/01/02 16:11:34";
 #else
-__RCSID("$NetBSD: rfc931.c,v 1.11 2016/03/16 21:38:22 christos Exp $");
+__RCSID("$NetBSD: rfc931.c,v 1.12 2016/03/16 22:32:32 christos Exp $");
 #endif
 #endif
 
@@ -87,7 +87,7 @@ rfc931(struct sockaddr *rmt_sin, struct 
 charuser[256];			/* XXX */
 charbuffer[512];		/* XXX */
 char   *cp;
-static char   *result = unknown;
+char   * volatile result = unknown;
 FILE   *fp;
 volatile int salen;
 u_short * volatile rmt_portp;



CVS commit: src/lib/libwrap

2016-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb 17 19:52:20 UTC 2016

Modified Files:
src/lib/libwrap: hosts_access.c

Log Message:
PR/50823: David Binderman: Limit scanf width


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libwrap/hosts_access.c

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



CVS commit: src/lib/libwrap

2016-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb 17 19:52:20 UTC 2016

Modified Files:
src/lib/libwrap: hosts_access.c

Log Message:
PR/50823: David Binderman: Limit scanf width


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libwrap/hosts_access.c

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

Modified files:

Index: src/lib/libwrap/hosts_access.c
diff -u src/lib/libwrap/hosts_access.c:1.20 src/lib/libwrap/hosts_access.c:1.21
--- src/lib/libwrap/hosts_access.c:1.20	Wed Mar 21 06:10:37 2012
+++ src/lib/libwrap/hosts_access.c	Wed Feb 17 14:52:20 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: hosts_access.c,v 1.20 2012/03/21 10:10:37 matt Exp $	*/
+/*	$NetBSD: hosts_access.c,v 1.21 2016/02/17 19:52:20 christos Exp $	*/
 
  /*
   * This module implements a simple access control language that is based on
@@ -24,7 +24,7 @@
 #if 0
 static char sccsid[] = "@(#) hosts_access.c 1.21 97/02/12 02:13:22";
 #else
-__RCSID("$NetBSD: hosts_access.c,v 1.20 2012/03/21 10:10:37 matt Exp $");
+__RCSID("$NetBSD: hosts_access.c,v 1.21 2016/02/17 19:52:20 christos Exp $");
 #endif
 #endif
 
@@ -309,12 +309,12 @@ host_match(char *tok, struct host_info *
 static int
 hostfile_match(char *path, struct host_info *host)
 {
-chartok[BUFSIZ];
+chartok[512];
 int match = NO;
 FILE   *fp;
 
 if ((fp = fopen(path, "r")) != 0) {
-	while (fscanf(fp, "%s", tok) == 1 && !(match = host_match(tok, host)))
+	while (fscanf(fp, "%511s", tok) == 1 && !(match = host_match(tok, host)))
 	 /* void */ ;
 	fclose(fp);
 } else if (errno != ENOENT) {



CVS commit: src/lib/libwrap

2015-10-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Oct 14 15:54:21 UTC 2015

Modified Files:
src/lib/libwrap: diag.c tcpd.h

Log Message:
these are syslog-like


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libwrap/diag.c
cvs rdiff -u -r1.14 -r1.15 src/lib/libwrap/tcpd.h

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



CVS commit: src/lib/libwrap

2012-03-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Mar 22 22:58:15 UTC 2012

Modified Files:
src/lib/libwrap: diag.c

Log Message:
Format the diagnostic with vasprintf once and use plain syslog instead
of messing with format strings.


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

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

Modified files:

Index: src/lib/libwrap/diag.c
diff -u src/lib/libwrap/diag.c:1.9 src/lib/libwrap/diag.c:1.10
--- src/lib/libwrap/diag.c:1.9	Wed Mar 21 10:10:37 2012
+++ src/lib/libwrap/diag.c	Thu Mar 22 22:58:15 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: diag.c,v 1.9 2012/03/21 10:10:37 matt Exp $	*/
+/*	$NetBSD: diag.c,v 1.10 2012/03/22 22:58:15 joerg Exp $	*/
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = @(#) diag.c 1.1 94/12/28 17:42:20;
 #else
-__RCSID($NetBSD: diag.c,v 1.9 2012/03/21 10:10:37 matt Exp $);
+__RCSID($NetBSD: diag.c,v 1.10 2012/03/22 22:58:15 joerg Exp $);
 #endif
 #endif
 
@@ -25,6 +25,7 @@ __RCSID($NetBSD: diag.c,v 1.9 2012/03/2
 #include syslog.h
 #include stdarg.h
 #include stdio.h
+#include stdlib.h
 #include setjmp.h
 #include string.h
 #include errno.h
@@ -37,46 +38,33 @@ struct tcpd_context tcpd_context;
 jmp_buf tcpd_buf;
 
 static void tcpd_diag(int, const char *, const char *, va_list)
-	__attribute__((__format__(__printf__, 3, 0)));
+__printflike(3,0);
 
 /* tcpd_diag - centralize error reporter */
 
 static void
-tcpd_diag(int severity, const char *tag, const char *format, va_list ap)
+tcpd_diag(int severity, const char *tag, const char *fmt, va_list ap)
 {
-charfmt[BUFSIZ];
-charbuf[BUFSIZ];
-size_t  i, o;
+char *buf;
 int oerrno;
 
 /* save errno in case we need it */
 oerrno = errno;
 
+if (vasprintf(buf, fmt, ap) == -1)
+	buf = __UNCONST(fmt);
+
+errno = oerrno;
+
 /* contruct the tag for the log entry */
 if (tcpd_context.file)
-	(void)snprintf(buf, sizeof buf, %s: %s, line %d: ,
-		tag, tcpd_context.file, tcpd_context.line);
+	syslog(severity, %s: %s, line %d: %s,
+	tag, tcpd_context.file, tcpd_context.line, buf);
 else
-	(void)snprintf(buf, sizeof buf, %s: , tag);
+	syslog(severity, %s: %s, tag, buf);
 
-/* change % to %% in tag before appending the format */
-for (i = 0, o = 0; buf[i] != '\0'; ) {
-	if (buf[i] == '%') {
-	fmt[o] = '%';
-	if (o  sizeof(fmt) - 1)
-		o++;
-	}
-	fmt[o] = buf[i++];
-	if (o  sizeof(fmt) - 1)
-	o++;
-}
-
-/* append format and force null termination */
-fmt[o] = '\0';
-(void)strlcat(fmt, format, sizeof(fmt) - o);
-
-errno = oerrno;
-vsyslog(severity, fmt, ap);
+if (buf != fmt)
+free(buf);
 }
 
 /* tcpd_warn - report problem of some sort and proceed */



CVS commit: src/lib/libwrap

2012-03-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Mar 22 22:58:15 UTC 2012

Modified Files:
src/lib/libwrap: diag.c

Log Message:
Format the diagnostic with vasprintf once and use plain syslog instead
of messing with format strings.


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

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