]> git.decadent.org.uk Git - odhcp6c.git/commitdiff
Merge pull request #42 from bwhacks/logic-fixes
authorSteven Barth <steven@midlink.org>
Thu, 28 Jan 2016 19:06:46 +0000 (20:06 +0100)
committerSteven Barth <steven@midlink.org>
Thu, 28 Jan 2016 19:06:46 +0000 (20:06 +0100)
Logic fixes

src/odhcp6c.c
src/script.c

index 1714d629b7cc38a7b3816cfaac58af5a2420baa0..59f6390801152d82264e3a45516e8979a8ca5a4e 100644 (file)
@@ -619,7 +619,7 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed)
        uint8_t *start = odhcp6c_get_state(state, &len);
        for (struct odhcp6c_entry *c = (struct odhcp6c_entry*)start;
                        (uint8_t*)c < &start[len] && &c->auxtarget[c->auxlen] <= &start[len];
-                       c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen])) {
+                       ) {
                if (c->t1 < elapsed)
                        c->t1 = 0;
                else if (c->t1 != UINT32_MAX)
@@ -640,8 +640,12 @@ static void odhcp6c_expire_list(enum odhcp6c_state state, uint32_t elapsed)
                else if (c->valid != UINT32_MAX)
                        c->valid -= elapsed;
 
-               if (!c->valid)
+               if (!c->valid) {
                        odhcp6c_remove_state(state, ((uint8_t*)c) - start, sizeof(*c) + c->auxlen);
+                       start = odhcp6c_get_state(state, &len);
+               } else {
+                       c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen]);
+               }
        }
 }
 
index 357933105d35d56f5718fbad56b30595dbe80557..1533510dbab56c8d8394298ecf48c844b9255380 100644 (file)
@@ -105,7 +105,9 @@ static void ipv6_to_env(const char *name,
                buf_len += strlen(&buf[buf_len]);
                buf[buf_len++] = ' ';
        }
-       buf[buf_len - 1] = '\0';
+       if (buf[buf_len - 1] == ' ')
+               buf_len--;
+       buf[buf_len] = '\0';
        putenv(buf);
 }
 
@@ -126,7 +128,9 @@ static void fqdn_to_env(const char *name, const uint8_t *fqdn, size_t len)
                buf_len += strlen(&buf[buf_len]);
                buf[buf_len++] = ' ';
        }
-       buf[buf_len - 1] = '\0';
+       if (buf[buf_len - 1] == ' ')
+               buf_len--;
+       buf[buf_len] = '\0';
        putenv(buf);
 }
 
@@ -201,7 +205,9 @@ static void entry_to_env(const char *name, const void *data, size_t len, enum en
                buf[buf_len++] = ' ';
        }
 
-       buf[buf_len - 1] = '\0';
+       if (buf[buf_len - 1] == ' ')
+               buf_len--;
+       buf[buf_len] = '\0';
        putenv(buf);
 }
 
@@ -220,7 +226,9 @@ static void search_to_env(const char *name, const uint8_t *start, size_t len)
                *c++ = ' ';
        }
 
-       c[-1] = '\0';
+       if (c[-1] == ' ')
+               c--;
+       *c = '\0';
        putenv(buf);
 }