am e0988b4b: am 8ee8b362: am c8cd001c: am 18ccfeaf: am ddde5cb3: am ab760879: Fun with buffer overrruns.

* commit 'e0988b4b7e6de2444482714041497c66ac459efc':
  Fun with buffer overrruns.
diff --git a/Android.mk b/Android.mk
index 1eb13dd..216ee3a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -8,17 +8,15 @@
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := arp.c bind.c common.c control.c dhcp.c dhcpcd.c duid.c \
 	eloop.c if-options.c if-pref.c ipv4ll.c net.c signals.c configure.c \
-	if-linux.c if-linux-wireless.c lpf.c compat/getline.c \
+	if-linux.c if-linux-wireless.c lpf.c \
 	platform-linux.c compat/closefrom.c ifaddrs.c ipv6rs.c
 
-#LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
 LOCAL_SHARED_LIBRARIES := libc libcutils libnetutils
 LOCAL_MODULE = dhcpcd
 include $(BUILD_EXECUTABLE)
 
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := showlease.c
-#LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
 LOCAL_SHARED_LIBRARIES := libc
 LOCAL_MODULE = showlease
 LOCAL_MODULE_TAGS := debug
diff --git a/android.conf b/android.conf
index bde048c..5f5fd54 100755
--- a/android.conf
+++ b/android.conf
@@ -1,6 +1,9 @@
 # dhcpcd configuration for Android Wi-Fi interface
 # See dhcpcd.conf(5) for details.
 
+# IPv6 RS/RA processing is handled by the kernel. See also http://b/15268738
+noipv6rs
+
 interface wlan0
 # dhcpcd-run-hooks uses these options.
 option subnet_mask, routers, domain_name_servers, domain_name, domain_search
diff --git a/compat/arc4random.c b/compat/arc4random.c
deleted file mode 100644
index 48ef29d..0000000
--- a/compat/arc4random.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Arc4 random number generator for OpenBSD.
- * Copyright 1996 David Mazieres <dm@lcs.mit.edu>.
- *
- * Modification and redistribution in source and binary forms is
- * permitted provided that due credit is given to the author and the
- * OpenBSD project by leaving this copyright notice intact.
- */
-
-/*
- * This code is derived from section 17.1 of Applied Cryptography,
- * second edition, which describes a stream cipher allegedly
- * compatible with RSA Labs "RC4" cipher (the actual description of
- * which is a trade secret).  The same algorithm is used as a stream
- * cipher called "arcfour" in Tatu Ylonen's ssh package.
- *
- * Here the stream cipher has been modified always to include the time
- * when initializing the state.  That makes it impossible to
- * regenerate the same random sequence twice, so this can't be used
- * for encryption, but will generate good random numbers.
- *
- * RC4 is a registered trademark of RSA Laboratories.
- */
-
-#include <sys/time.h>
-
-#include <fcntl.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "arc4random.h"
-
-struct arc4_stream {
-	uint8_t i;
-	uint8_t j;
-	uint8_t s[256];
-};
-
-static int rs_initialized;
-static struct arc4_stream rs;
-static int arc4_count;
-
-static void
-arc4_init(struct arc4_stream *as)
-{
-	int n;
-
-	for (n = 0; n < 256; n++)
-		as->s[n] = n;
-	as->i = 0;
-	as->j = 0;
-}
-
-static void
-arc4_addrandom(struct arc4_stream *as, unsigned char *dat, int datlen)
-{
-	int n;
-	uint8_t si;
-
-	as->i--;
-	for (n = 0; n < 256; n++) {
-		as->i = (as->i + 1);
-		si = as->s[as->i];
-		as->j = (as->j + si + dat[n % datlen]);
-		as->s[as->i] = as->s[as->j];
-		as->s[as->j] = si;
-	}
-	as->j = as->i;
-}
-
-static uint8_t
-arc4_getbyte(struct arc4_stream *as)
-{
-	uint8_t si, sj;
-
-	as->i = (as->i + 1);
-	si = as->s[as->i];
-	as->j = (as->j + si);
-	sj = as->s[as->j];
-	as->s[as->i] = sj;
-	as->s[as->j] = si;
-	return (as->s[(si + sj) & 0xff]);
-}
-
-static uint32_t
-arc4_getword(struct arc4_stream *as)
-{
-	uint32_t val;
-
-	val = arc4_getbyte(as) << 24;
-	val |= arc4_getbyte(as) << 16;
-	val |= arc4_getbyte(as) << 8;
-	val |= arc4_getbyte(as);
-	return val;
-}
-
-static void
-arc4_stir(struct arc4_stream *as)
-{
-	int fd;
-	struct {
-		struct timeval tv;
-		unsigned int rnd[(128 - sizeof(struct timeval)) /
-			sizeof(unsigned int)];
-	}       rdat;
-	int n;
-
-	gettimeofday(&rdat.tv, NULL);
-	fd = open("/dev/urandom", O_RDONLY);
-	if (fd != -1) {
-		n = read(fd, rdat.rnd, sizeof(rdat.rnd));
-		close(fd);
-	}
-
-	/* fd < 0?  Ah, what the heck. We'll just take
-	 * whatever was on the stack... */
-	arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
-
-	/*
-	 * Throw away the first N words of output, as suggested in the
-	 * paper "Weaknesses in the Key Scheduling Algorithm of RC4"
-	 * by Fluher, Mantin, and Shamir.  (N = 256 in our case.)
-	 */
-	for (n = 0; n < 256 * 4; n++)
-		arc4_getbyte(as);
-	arc4_count = 1600000;
-}
-
-void
-arc4random_stir()
-{
-
-	if (!rs_initialized) {
-		arc4_init(&rs);
-		rs_initialized = 1;
-	}
-	arc4_stir(&rs);
-}
-
-void
-arc4random_addrandom(unsigned char *dat, int datlen)
-{
-
-	if (!rs_initialized)
-		arc4random_stir();
-	arc4_addrandom(&rs, dat, datlen);
-}
-
-uint32_t
-arc4random()
-{
-
-	arc4_count -= 4;
-	if (!rs_initialized || arc4_count <= 0)
-		arc4random_stir();
-	return arc4_getword(&rs);
-}
diff --git a/compat/arc4random.h b/compat/arc4random.h
deleted file mode 100644
index 2b10902..0000000
--- a/compat/arc4random.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* 
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * 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 AUTHOR 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 AUTHOR 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.
- */
-
-#ifndef ARC4RANDOM_H
-#define ARC4RANDOM_H
-
-#include <stdint.h>
-
-void arc4random_stir(void);
-void arc4random_addrandom(unsigned char *, int);
-uint32_t arc4random(void);
-#endif
diff --git a/compat/closefrom.c b/compat/closefrom.c
index 664c4bc..9d34a53 100644
--- a/compat/closefrom.c
+++ b/compat/closefrom.c
@@ -32,11 +32,18 @@
 int
 closefrom(int fd)
 {
-	int max = getdtablesize();
-	int i;
-	int r = 0;
+	long max;
+	int i, r;
 
-	for (i = fd; i < max; i++)
-		r += close(i);
+#ifdef _SC_OPEN_MAX
+	max = sysconf(_SC_OPEN_MAX);
+#else
+	max = getdtablesize();
+#endif
+	r = 0;
+	for (i = fd; i < max; i++) {
+		if (close(i) == -1)
+			r = -1;
+	}
 	return r;
 }
diff --git a/compat/getline.c b/compat/getline.c
deleted file mode 100644
index 3f01b66..0000000
--- a/compat/getline.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* 
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * 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 AUTHOR 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 AUTHOR 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 <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "getline.h"
-
-/* Redefine a small buffer for our simple text config files */
-#undef BUFSIZ
-#define BUFSIZ 128
-
-ssize_t
-getline(char ** __restrict buf, size_t * __restrict buflen,
-    FILE * __restrict fp)
-{
-	size_t bytes, newlen;
-	char *newbuf, *p;
-	
-	if (buf == NULL || buflen == NULL) {
-		errno = EINVAL;
-		return -1;
-	}
-	if (*buf == NULL)
-		*buflen = 0;
-	
-	bytes = 0;
-	do {
-		if (feof(fp))
-			break;
-		if (*buf == NULL || bytes != 0) {
-			newlen = *buflen + BUFSIZ;
-			newbuf = realloc(*buf, newlen);
-			if (newbuf == NULL)
-				return -1;
-			*buf = newbuf;
-			*buflen = newlen;
-		}
-		p = *buf + bytes;
-		memset(p, 0, BUFSIZ);
-		if (fgets(p, BUFSIZ, fp) == NULL)
-			break;
-		bytes += strlen(p);
-	} while (bytes == 0 || *(*buf + (bytes - 1)) != '\n');
-	if (bytes == 0)
-		return -1;
-	return bytes;
-}
diff --git a/compat/getline.h b/compat/getline.h
deleted file mode 100644
index 390632c..0000000
--- a/compat/getline.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* 
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * 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 AUTHOR 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 AUTHOR 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.
- */
-
-#ifndef GETLINE_H
-#define GETLINE_H
-
-#include <sys/types.h>
-#include <stdio.h>
-
-ssize_t getline(char ** __restrict buf, size_t * __restrict buflen,
-    FILE * __restrict fp);
-#endif
diff --git a/compat/linkaddr.c b/compat/linkaddr.c
deleted file mode 100644
index c4e6fa5..0000000
--- a/compat/linkaddr.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * 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.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)linkaddr.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/if_dl.h>
-
-#include <string.h>
-
-/* States*/
-#define NAMING	0
-#define GOTONE	1
-#define GOTTWO	2
-#define RESET	3
-/* Inputs */
-#define	DIGIT	(4*0)
-#define	END	(4*1)
-#define DELIM	(4*2)
-#define LETTER	(4*3)
-
-void
-link_addr(addr, sdl)
-	const char *addr;
-	struct sockaddr_dl *sdl;
-{
-	char *cp = sdl->sdl_data;
-	char *cplim = sdl->sdl_len + (char *)(void *)sdl;
-	int byte = 0, state = NAMING;
-	int newaddr = 0;
-
-	(void)memset(&sdl->sdl_family, 0, (size_t)sdl->sdl_len - 1);
-	sdl->sdl_family = AF_LINK;
-	do {
-		state &= ~LETTER;
-		if ((*addr >= '0') && (*addr <= '9')) {
-			newaddr = *addr - '0';
-		} else if ((*addr >= 'a') && (*addr <= 'f')) {
-			newaddr = *addr - 'a' + 10;
-		} else if ((*addr >= 'A') && (*addr <= 'F')) {
-			newaddr = *addr - 'A' + 10;
-		} else if (*addr == 0) {
-			state |= END;
-		} else if (state == NAMING &&
-			   (((*addr >= 'A') && (*addr <= 'Z')) ||
-			   ((*addr >= 'a') && (*addr <= 'z'))))
-			state |= LETTER;
-		else
-			state |= DELIM;
-		addr++;
-		switch (state /* | INPUT */) {
-		case NAMING | DIGIT:
-		case NAMING | LETTER:
-			*cp++ = addr[-1];
-			continue;
-		case NAMING | DELIM:
-			state = RESET;
-			sdl->sdl_nlen = cp - sdl->sdl_data;
-			continue;
-		case GOTTWO | DIGIT:
-			*cp++ = byte;
-			/* FALLTHROUGH */
-		case RESET | DIGIT:
-			state = GOTONE;
-			byte = newaddr;
-			continue;
-		case GOTONE | DIGIT:
-			state = GOTTWO;
-			byte = newaddr + (byte << 4);
-			continue;
-		default: /* | DELIM */
-			state = RESET;
-			*cp++ = byte;
-			byte = 0;
-			continue;
-		case GOTONE | END:
-		case GOTTWO | END:
-			*cp++ = byte;
-			/* FALLTHROUGH */
-		case RESET | END:
-			break;
-		}
-		break;
-	} while (cp < cplim);
-	sdl->sdl_alen = cp - LLADDR(sdl);
-	newaddr = cp - (char *)(void *)sdl;
-	if ((size_t) newaddr > sizeof(*sdl))
-		sdl->sdl_len = newaddr;
-	return;
-}
diff --git a/compat/strlcpy.c b/compat/strlcpy.c
deleted file mode 100644
index e44d19c..0000000
--- a/compat/strlcpy.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/* 
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * 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 AUTHOR 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 AUTHOR 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 <sys/types.h>
-
-#include "strlcpy.h"
-
-size_t
-strlcpy(char *dst, const char *src, size_t size)
-{
-	const char *s = src;
-	size_t n = size;
-
-	if (n && --n)
-		do {
-			if (!(*dst++ = *src++))
-				break;
-		} while (--n);
-
-	if (!n) {
-		if (size)
-			*dst = '\0';
-		while (*src++);
-	}
-
-	return src - s - 1;
-}
diff --git a/compat/strlcpy.h b/compat/strlcpy.h
deleted file mode 100644
index 0ff3854..0000000
--- a/compat/strlcpy.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* 
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2009 Roy Marples <roy@marples.name>
- * All rights reserved
-
- * 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 AUTHOR 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 AUTHOR 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.
- */
-
-#ifndef STRLCPY_H
-#define STRLCPY_H
-
-#include <sys/types.h>
-
-size_t strlcpy(char *, const char *, size_t);
-#endif
diff --git a/config.h b/config.h
index 180c63e..e9f0af3 100644
--- a/config.h
+++ b/config.h
@@ -4,15 +4,6 @@
 #define LIBEXECDIR	"/system/etc/dhcpcd"
 #define DBDIR		"/data/misc/dhcp"
 #define RUNDIR		"/data/misc/dhcp"
-#include "compat/arc4random.h"
 #include "compat/closefrom.h"
-#include "compat/strlcpy.h"
-#include "compat/getline.h"
 
-#ifndef MAX
-#define MAX(a,b)	((a) >= (b) ? (a) : (b))
-#endif
-
-#ifndef MIN
-#define MIN(a,b)	((a) <= (b) ? (a) : (b))
-#endif
+#include <sys/param.h>
diff --git a/dhcp.c b/dhcp.c
index 7675b5b..0a1d220 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -356,7 +356,7 @@
 		case DHO_OPTIONSOVERLOADED:
 			/* Ensure we only get this option once */
 			if (!overl)
-				overl = p[1];
+				overl = 0x80 | p[1];
 			break;
 		}
 		l = *p++;
diff --git a/dhcpcd.c b/dhcpcd.c
index bac33f3..6eae970 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -74,7 +74,7 @@
 
 #ifdef ANDROID
 #include <sys/capability.h>
-#include <linux/prctl.h>
+#include <sys/prctl.h>
 #include <cutils/properties.h>
 #include <private/android_filesystem_config.h>
 #endif
diff --git a/if-options.c b/if-options.c
index 3f52bfe..4fbdf13 100644
--- a/if-options.c
+++ b/if-options.c
@@ -796,7 +796,13 @@
 	ifo = xzalloc(sizeof(*ifo));
 	ifo->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE | DHCPCD_LINK;
 	ifo->options |= DHCPCD_ARP | DHCPCD_IPV4LL;
+#ifndef ANDROID
+	/* On Android, don't enable IPv6 RS processing. This is because we
+	 * already process RAs in the kernel and netd and because we've seen
+	 * dhcpcd crashes when parsing certain RA options.
+	 * See http://b/15268738 and http://b/15779617 . */
 	ifo->options |= DHCPCD_IPV6RS | DHCPCD_IPV6RA_REQRDNSS;
+#endif
 	ifo->timeout = DEFAULT_TIMEOUT;
 	ifo->reboot = DEFAULT_REBOOT;
 	ifo->metric = -1;