dhclient - Fix old bug that could cause lease mangling.
authorAntonio Huete Jimenez <tuxillo@quantumachine.net>
Wed, 1 Aug 2012 18:06:32 +0000 (20:06 +0200)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Sun, 19 Aug 2012 14:30:17 +0000 (16:30 +0200)
Taken-from: OpenBSD

sbin/dhclient/clparse.c
sbin/dhclient/dhclient.c

index 1196349..20e57a6 100644 (file)
@@ -1,5 +1,4 @@
-/*     $OpenBSD: clparse.c,v 1.34 2007/02/14 23:19:26 deraadt Exp $    */
-/*     $DragonFly: src/sbin/dhclient/clparse.c,v 1.1 2008/08/30 16:07:58 hasso Exp $   */
+/*     $OpenBSD: src/sbin/dhclient/clparse.c,v 1.35 2009/05/27 15:04:34 stevesk Exp $  */
 
 /* Parser for dhclient config and lease files... */
 
@@ -450,7 +449,8 @@ parse_client_lease_statement(FILE *cfile, int is_static)
                                client->leases = lp->next;
                        free_client_lease(lp);
                        break;
-               }
+               } else
+                       pl = lp;
        }
 
        /*
index 5f810ea..d65e29e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: src/sbin/dhclient/dhclient.c,v 1.126 2009/05/20 20:37:43 thib Exp $   */
+/*     $OpenBSD: src/sbin/dhclient/dhclient.c,v 1.127 2009/05/25 00:17:40 stevesk Exp $        */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -168,6 +168,7 @@ routehandler(void)
        struct sockaddr *sa;
        struct iaddr a;
        ssize_t n;
+       char *errmsg, buf[64];
 
        do {
                n = read(routefd, &msg, sizeof(msg));
@@ -186,8 +187,10 @@ routehandler(void)
                if (findproto((char *)(ifam + 1), ifam->ifam_addrs) != AF_INET)
                        break;
                sa = get_ifa((char *)(ifam + 1), ifam->ifam_addrs);
-               if (sa == NULL)
+               if (sa == NULL) {
+                       errmsg = "sa == NULL";
                        goto die;
+               }
 
                if ((a.len = sizeof(struct in_addr)) > sizeof(a.iabuf))
                        error("king bula sez: len mismatch");
@@ -203,7 +206,9 @@ routehandler(void)
                    addr_eq(a, client->alias->address)))
                        /* new addr is the one we set */
                        break;
-
+               snprintf(buf, sizeof(buf), "%s: %s",
+                   "new address not one we set", piaddr(a));
+               errmsg = buf;
                goto die;
        case RTM_DELADDR:
                ifam = (struct ifa_msghdr *)rtm;
@@ -213,13 +218,16 @@ routehandler(void)
                        break;
                if (scripttime == 0 || t < scripttime + 10)
                        break;
+               errmsg = "interface address deleted";
                goto die;
        case RTM_IFINFO:
                ifm = (struct if_msghdr *)rtm;
                if (ifm->ifm_index != ifi->index)
                        break;
-               if ((rtm->rtm_flags & RTF_UP) == 0)
+               if ((rtm->rtm_flags & RTF_UP) == 0) {
+                       errmsg = "interface down";
                        goto die;
+               }
 
                linkstat =
                    LINK_STATE_IS_UP(ifm->ifm_data.ifi_link_state) ? 1 : 0;
@@ -237,8 +245,10 @@ routehandler(void)
        case RTM_IFANNOUNCE:
                ifan = (struct if_announcemsghdr *)rtm;
                if (ifan->ifan_what == IFAN_DEPARTURE &&
-                   ifan->ifan_index == ifi->index)
+                   ifan->ifan_index == ifi->index) {
+                       errmsg = "interface departure";
                        goto die;
+               }
                break;
        default:
                break;
@@ -250,7 +260,7 @@ die:
        if (client->alias)
                script_write_params("alias_", client->alias);
        script_go();
-       exit(1);
+       error("routehandler: %s", errmsg);
 }
 
 int