[Swan-dev] [PATCH] ikev2_ipsec: include limits.h for HOST_NAME_MAX

Antony Antony antony at phenome.org
Mon Aug 14 19:20:52 UTC 2017


interesting! 

could you please try the attached patch?

It should be consistent with the use id.c and whack. The comment there 
suggested unistd.h. 

https://github.com/libreswan/libreswan/blob/master/lib/libswan/id.c#L26 
#ifndef HOST_NAME_MAX /* POSIX 1003.1-2001 says <unistd.h> defines this */

Now I think the comment is for OpenBSD.  Linux it is in limits.h which 
should come via sysdep.h

https://github.com/libreswan/libreswan/blob/master/ports/linux/include/sysdep.h#L8
#include <limits.h>
/* POSIX 1003.1-2001 says <unistd.h> defines this */

Here is my proposed patch. 

Actually, we may have to use another constant. Now it is 64, which is 
probably short, I was thinking it is 255.

-antony

On Mon, Aug 14, 2017 at 03:09:18PM +0300, Timo Teras wrote:
> HOST_NAME_MAX is defined in limits.h according to POSIX. Include it
> appropriately in ikev2_ipseckey.c. Namely, this fixes a build failure
> on ppc64le with musl c-library:
> 
> libreswan-3.21/programs/pluto/ikev2_ipseckey.c: In function 'build_dns_name':
> libreswan-3.21/programs/pluto/ikev2_ipseckey.c:725:22: error: 'HOST_NAME_MAX' undeclared (first use in this function)
>   if (id->name.len >= HOST_NAME_MAX)
>                       ^~~~~~~~~~~~~
> libreswan-3.21/programs/pluto/ikev2_ipseckey.c:725:22: note: each undeclared identifier is reported only once for each function it appears in
> libreswan-3.21/programs/pluto/ikev2_ipseckey.c: In function 'qry_st_init':
> libreswan-3.21/programs/pluto/ikev2_ipseckey.c:773:15: error: 'HOST_NAME_MAX' undeclared (first use in this function)
>   char log_buf[HOST_NAME_MAX * 2]; /* this is local */
>                ^~~~~~~~~~~~~
> 
> diff -ru libreswan-3.21.orig/programs/pluto/ikev2_ipseckey.c libreswan-3.21/programs/pluto/ikev2_ipseckey.c
> --- libreswan-3.21.orig/programs/pluto/ikev2_ipseckey.c	2017-08-09 20:47:34.000000000 +0000
> +++ libreswan-3.21/programs/pluto/ikev2_ipseckey.c	2017-08-14 12:00:26.380840562 +0000
> @@ -23,6 +23,7 @@
>  #include <stddef.h>
>  #include <stdlib.h>
>  #include <unistd.h>
> +#include <limits.h>
>  #include <errno.h>
>  #include <arpa/inet.h> /* for inet_ntop */
>  #include <arpa/nameser.h>
> _______________________________________________
> Swan-dev mailing list
> Swan-dev at lists.libreswan.org
> https://lists.libreswan.org/mailman/listinfo/swan-dev
-------------- next part --------------
>From ee7952c5112a2b08c1b196cabd946e0b3c3dc74a Mon Sep 17 00:00:00 2001
From: Antony Antony <antony at phenome.org>
Date: Mon, 14 Aug 2017 20:52:18 +0200
Subject: [PATCH] posix: use HOST_NAME_MAX consitently from limits.h

---
 lib/libswan/id.c                | 5 +----
 ports/linux/include/sysdep.h    | 2 +-
 programs/pluto/ikev2_ipseckey.c | 2 +-
 programs/pluto/rcv_whack.c      | 4 ----
 4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/lib/libswan/id.c b/lib/libswan/id.c
index 06cc751..b89650a 100644
--- a/lib/libswan/id.c
+++ b/lib/libswan/id.c
@@ -22,10 +22,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <unistd.h>
-#ifndef HOST_NAME_MAX	/* POSIX 1003.1-2001 says <unistd.h> defines this */
-#define HOST_NAME_MAX 255	/* upper bound, according to SUSv2 */
-#endif
 
 #include <libreswan.h>
 
@@ -34,6 +30,7 @@
 #include "libreswan/passert.h"
 #include "lswalloc.h"
 #include "lswlog.h"
+#include "sysdep.h"
 #include "id.h"
 #include "x509.h"
 #include <cert.h>
diff --git a/ports/linux/include/sysdep.h b/ports/linux/include/sysdep.h
index deb2ac1..b782b2c 100644
--- a/ports/linux/include/sysdep.h
+++ b/ports/linux/include/sysdep.h
@@ -5,7 +5,7 @@
 #define TimeZoneOffset timezone
 
 #include <limits.h>
-/* POSIX 1003.1-2001 says <unistd.h> defines this */
+/* POSIX 1003.1-2001 says <limits.h> defines this */
 #ifndef HOST_NAME_MAX
 /* some don't even use _POSIX_HOST_NAME_MAX */
 # ifdef _POSIX_HOST_NAME_MAX
diff --git a/programs/pluto/ikev2_ipseckey.c b/programs/pluto/ikev2_ipseckey.c
index 45872ef..1d32d37 100644
--- a/programs/pluto/ikev2_ipseckey.c
+++ b/programs/pluto/ikev2_ipseckey.c
@@ -22,7 +22,6 @@
 #include <string.h>
 #include <stddef.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <errno.h>
 #include <arpa/inet.h> /* for inet_ntop */
 #include <arpa/nameser.h>
@@ -31,6 +30,7 @@
 #include "unbound-event.h"
 #include "libreswan.h"
 #include "lswlog.h"
+#include "sysdep.h"
 #include "defs.h"
 #include "log.h"
 #include "constants.h" /* for demux.h */
diff --git a/programs/pluto/rcv_whack.c b/programs/pluto/rcv_whack.c
index baa9fdf..9a53ed5 100644
--- a/programs/pluto/rcv_whack.c
+++ b/programs/pluto/rcv_whack.c
@@ -28,10 +28,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#ifndef HOST_NAME_MAX           /* POSIX 1003.1-2001 says <unistd.h> defines this */
-# define HOST_NAME_MAX  255     /* upper bound, according to SUSv2 */
-#endif
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
-- 
2.9.4



More information about the Swan-dev mailing list