Patchwork Fix getifaddrs, freeifaddrs namespace on non-Linux

login
register
mail settings
Submitter Aurelien Jarno
Date Dec. 13, 2015, 11:12 p.m.
Message ID <1450048348-1536-1-git-send-email-aurelien@aurel32.net>
Download mbox | patch
Permalink /patch/9997/
State New
Headers show

Comments

Aurelien Jarno - Dec. 13, 2015, 11:12 p.m.
Commit 7f994279 addressed the getifaddrs, freeifaddrs namespace issue on
Linux, but this issue is also present on non-Linux via check_pf:

  freeaddrinfo -> [libc.a(getaddrinfo.o)] __check_pf -> libc.a(check_pf.o)] freeifaddrs

This patch fixes this issue by fixing the generic check_pf version to
call __getifaddrs and __freeifaddrs instead of getifaddrs and
freeifaddrs. As check_pf.c is also included directly from nscd/gai.c,
we need to use defines to revert this change there.
---
 ChangeLog         | 9 +++++++++
 include/ifaddrs.h | 2 ++
 inet/check_pf.c   | 4 ++--
 nscd/gai.c        | 2 ++
 4 files changed, 15 insertions(+), 2 deletions(-)
Andreas Schwab - Dec. 14, 2015, 8:58 a.m.
Aurelien Jarno <aurelien@aurel32.net> writes:

> diff --git a/include/ifaddrs.h b/include/ifaddrs.h
> index 2787f21..7c52ccf 100644
> --- a/include/ifaddrs.h
> +++ b/include/ifaddrs.h
> @@ -3,7 +3,9 @@
>  #include <stdbool.h>
>  #include <stdint.h>
>  
> +extern __typeof(getifaddrs) __getifaddrs;
>  libc_hidden_proto (getifaddrs)
> +extern __typeof(freeifaddrs) __freeifaddrs;
>  libc_hidden_proto (freeifaddrs)

You need the hidden_proto on the __ names.

Andreas.
Aurelien Jarno - Dec. 18, 2015, 11:29 p.m.
On 2015-12-14 09:58, Andreas Schwab wrote:
> Aurelien Jarno <aurelien@aurel32.net> writes:
> 
> > diff --git a/include/ifaddrs.h b/include/ifaddrs.h
> > index 2787f21..7c52ccf 100644
> > --- a/include/ifaddrs.h
> > +++ b/include/ifaddrs.h
> > @@ -3,7 +3,9 @@
> >  #include <stdbool.h>
> >  #include <stdint.h>
> >  
> > +extern __typeof(getifaddrs) __getifaddrs;
> >  libc_hidden_proto (getifaddrs)
> > +extern __typeof(freeifaddrs) __freeifaddrs;
> >  libc_hidden_proto (freeifaddrs)
> 
> You need the hidden_proto on the __ names.

If I understand correctly doing so also means adding a hidden_def on
the __ names in ifaddrs.c. Is it correct?
Mike Frysinger - Dec. 29, 2015, 7:01 p.m.
On 19 Dec 2015 00:29, Aurelien Jarno wrote:
> On 2015-12-14 09:58, Andreas Schwab wrote:
> > Aurelien Jarno <aurelien@aurel32.net> writes:
> > > --- a/include/ifaddrs.h
> > > +++ b/include/ifaddrs.h
> > > @@ -3,7 +3,9 @@
> > >  #include <stdbool.h>
> > >  #include <stdint.h>
> > >  
> > > +extern __typeof(getifaddrs) __getifaddrs;
> > >  libc_hidden_proto (getifaddrs)
> > > +extern __typeof(freeifaddrs) __freeifaddrs;
> > >  libc_hidden_proto (freeifaddrs)
> > 
> > You need the hidden_proto on the __ names.
> 
> If I understand correctly doing so also means adding a hidden_def on
> the __ names in ifaddrs.c. Is it correct?

yep
-mike

Patch

diff --git a/ChangeLog b/ChangeLog
index 13be8a8..3fb0b90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@ 
+2015-12-12  Aurelien Jarno  <aurelien@aurel32.net>
+
+	* include/ifaddrs.h (__getifaddrs): Declare.
+	(__freeifaddrs): Declare.
+	* inet/check_pf.c (__check_pf): Call __getifaddrs instead of
+	getifaddrs.  Call __freeifaddrs instead of freeifaddrs.
+	* nscd/gai.c (__getifaddrs): Define to getifaddrs.
+	(__freeifaddrs): define to freeifaddrs.
+
 2015-12-11  Aurelien Jarno  <aurelien@aurel32.net>
 
 	* sysdeps/unix/sysv/linux/arm/ioperm.c: Do not include
diff --git a/include/ifaddrs.h b/include/ifaddrs.h
index 2787f21..7c52ccf 100644
--- a/include/ifaddrs.h
+++ b/include/ifaddrs.h
@@ -3,7 +3,9 @@ 
 #include <stdbool.h>
 #include <stdint.h>
 
+extern __typeof(getifaddrs) __getifaddrs;
 libc_hidden_proto (getifaddrs)
+extern __typeof(freeifaddrs) __freeifaddrs;
 libc_hidden_proto (freeifaddrs)
 
 struct in6addrinfo
diff --git a/inet/check_pf.c b/inet/check_pf.c
index 3739a95..c49d6b5 100644
--- a/inet/check_pf.c
+++ b/inet/check_pf.c
@@ -32,7 +32,7 @@  __check_pf (bool *seen_ipv4, bool *seen_ipv6,
 
   /* Get the interface list via getifaddrs.  */
   struct ifaddrs *ifa = NULL;
-  if (getifaddrs (&ifa) != 0)
+  if (__getifaddrs (&ifa) != 0)
     {
       /* We cannot determine what interfaces are available.  Be
 	 pessimistic.  */
@@ -51,7 +51,7 @@  __check_pf (bool *seen_ipv4, bool *seen_ipv6,
     else if (runp->ifa_addr->sa_family == PF_INET6)
       *seen_ipv6 = true;
 
-  (void) freeifaddrs (ifa);
+  (void) __freeifaddrs (ifa);
 }
 
 
diff --git a/nscd/gai.c b/nscd/gai.c
index 9a52a97..dc289d6 100644
--- a/nscd/gai.c
+++ b/nscd/gai.c
@@ -29,6 +29,8 @@ 
 #define __strchrnul strchrnul
 #define __getline getline
 #define __qsort_r qsort_r
+#define __getifaddrs getifaddrs
+#define __freeifaddrs freeifaddrs
 /* nscd uses 1MB or 2MB thread stacks.  */
 #define __libc_use_alloca(size) (size <= __MAX_ALLOCA_CUTOFF)