Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 127208 Details for
Bug 187561
net-misc/dhcpcd-3.1.3 segfaults on ARP handling
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Attempt to fix ARP crash
dhcpcd-arp.patch (text/plain), 5.44 KB, created by
Roy Marples (RETIRED)
on 2007-08-07 20:38:25 UTC
(
hide
)
Description:
Attempt to fix ARP crash
Filename:
MIME Type:
Creator:
Roy Marples (RETIRED)
Created:
2007-08-07 20:38:25 UTC
Size:
5.44 KB
patch
obsolete
>Index: arp.c >=================================================================== >--- arp.c (revision 255) >+++ arp.c (working copy) >@@ -24,7 +24,7 @@ > #include <sys/select.h> > #include <sys/socket.h> > #include <netinet/in_systm.h> >-#ifdef __linux >+#ifdef __linux__ > #include <netinet/ether.h> > #include <netpacket/packet.h> > #endif >@@ -69,8 +69,8 @@ > > #ifdef ENABLE_ARP > >-static int send_arp (interface_t *iface, int op, struct in_addr sip, >- unsigned char *taddr, struct in_addr tip) >+static int send_arp (const interface_t *iface, int op, struct in_addr sip, >+ const unsigned char *taddr, struct in_addr tip) > { > struct arphdr *arp; > int arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr)); >@@ -84,7 +84,7 @@ > arp->ar_hln = iface->hwlen; > arp->ar_pln = sizeof (struct in_addr); > arp->ar_op = htons (op); >- memcpy (ar_sha (arp), &iface->hwaddr, arp->ar_hln); >+ memcpy (ar_sha (arp), iface->hwaddr, arp->ar_hln); > memcpy (ar_spa (arp), &sip, arp->ar_pln); > if (taddr) > memcpy (ar_tha (arp), taddr, arp->ar_hln); >@@ -105,6 +105,8 @@ > int nprobes = 0; > int nclaims = 0; > struct in_addr null_address; >+ struct timeval stopat; >+ struct timeval now; > > if (! iface->arpable) { > logger (LOG_DEBUG, "interface `%s' is not ARPable", iface->name); >@@ -117,7 +119,7 @@ > if (! open_socket (iface, true)) > return (0); > >- memset (&null_address, 0, sizeof (null_address)); >+ memset (&null_address, 0, sizeof (struct in_addr)); > > buffer = xmalloc (sizeof (char *) * iface->buffer_length); > >@@ -130,20 +132,26 @@ > int buflen = sizeof (char *) * iface->buffer_length; > fd_set rset; > int bytes; >- int s; >+ int s = 0; > >- tv.tv_sec = 0; >- tv.tv_usec = timeout; >+ /* Only select if we have a timeout */ >+ if (timeout > 0) { >+ tv.tv_sec = 0; >+ tv.tv_usec = timeout; > >- FD_ZERO (&rset); >- FD_SET (iface->fd, &rset); >- errno = 0; >- if ((s = select (FD_SETSIZE, &rset, NULL, NULL, &tv)) == -1) { >- if (errno != EINTR) >- logger (LOG_ERR, "select: `%s'", strerror (errno)); >- break; >- } else if (s == 0) { >- /* Timed out */ >+ FD_ZERO (&rset); >+ FD_SET (iface->fd, &rset); >+ >+ errno = 0; >+ if ((s = select (FD_SETSIZE, &rset, NULL, NULL, &tv)) == -1) { >+ if (errno != EINTR) >+ logger (LOG_ERR, "select: `%s'", strerror (errno)); >+ break; >+ } >+ } >+ >+ /* Timed out */ >+ if (s == 0) { > if (nprobes < NPROBES) { > nprobes ++; > timeout = PROBE_INTERVAL; >@@ -159,8 +167,23 @@ > retval = 0; > break; > } >+ >+ /* Setup our stop time */ >+ if (get_time (&stopat) != 0) >+ break; >+ stopat.tv_usec += timeout; >+ >+ continue; > } >- >+ >+ /* We maybe ARP flooded, so check our time */ >+ if (get_time (&now) != 0) >+ break; >+ if (timercmp (&now, &stopat, >)) { >+ timeout = 0; >+ continue; >+ } >+ > if (! FD_ISSET (iface->fd, &rset)) > continue; > >@@ -196,7 +219,7 @@ > > rp.c = (unsigned char *) ar_spa (reply); > rh.c = (unsigned char *) ar_sha (reply); >- >+ > /* Ensure the ARP reply is for the address we asked for */ > if (rp.a->s_addr != address.s_addr) > continue; >Index: Makefile >=================================================================== >--- Makefile (revision 264) >+++ Makefile (working copy) >@@ -1,4 +1,4 @@ >-VERSION = 3.1.3 >+VERSION = 3.1.4_pre2 > CFLAGS ?= -O2 -pipe > > # Should work for both GNU make and BSD make >@@ -49,12 +49,16 @@ > dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o duid.o \ > info.o interface.o ipv4ll.o logger.o signals.o socket.o > >-# By default we don't need to link to anything >-# Except on Darwin where we need -lresolv, so they need to uncomment this >-#dhcpcd_LIBS = -lresolv >+# These are nasty hacks to work out what libs we need to link to >+# We require librt for glibc bases systems >+LIBRT != ldd /bin/date 2>/dev/null | grep -q /librt.so && echo "-lrt" || exit 0 >+LIBRT ?= $(shell ldd /bin/date 2>/dev/null | grep -q /librt.so && echo "-lrt") > >+# Darwin needs this, but we have no way of detecting this atm >+#LIBRESOLV = -lresolv >+ > dhcpcd: $(dhcpcd_H) $(dhcpcd_OBJS) >- $(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(dhcpcd_LIBS) -o dhcpcd >+ $(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(LIBRT) $(LIBRESOLV) -o dhcpcd > > version.h: > echo '#define VERSION "$(VERSION)"' > version.h >Index: common.c >=================================================================== >--- common.c (revision 254) >+++ common.c (working copy) >@@ -76,17 +76,22 @@ > # endif > #endif > >-/* This requires us to link to rt on glibc, so we use sysinfo instead */ >-#ifdef __linux__ >-#include <sys/sysinfo.h> >-long uptime (void) >+/* Handy function to get the time. */ >+int get_time(struct timeval *tp) > { >- struct sysinfo info; >+ struct timespec ts; > >- sysinfo (&info); >- return info.uptime; >+ if (clock_gettime (CLOCK_MONOTONIC, &ts) == -1) { >+ logger (LOG_ERR, "clock_gettime: %s", strerror (errno)); >+ return (-1); >+ } >+ >+ tp->tv_sec = ts.tv_sec; >+ tp->tv_usec = ts.tv_nsec / 1000; >+ return (0); > } >-#elif __APPLE__ >+ >+#ifdef __APPLE__ > /* Darwin doesn't appear to have an uptime, so try and make one ourselves */ > long uptime (void) > { >Index: common.h >=================================================================== >--- common.h (revision 244) >+++ common.h (working copy) >@@ -23,6 +23,7 @@ > #define COMMON_H > > /* string.h pulls in features.h so the below define checks work */ >+#include <sys/time.h> > #include <string.h> > > /* Only GLIBC doesn't support strlcpy */ >@@ -36,6 +37,7 @@ > void srandomdev (void); > #endif > >+int get_time(struct timeval *tp); > long uptime (void); > void *xmalloc (size_t size); > char *xstrdup (const char *str);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 187561
:
127179
|
127197
|
127208
|
127285
|
127348