]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: buf2ip6 must not modify output on failure
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Dec 2013 10:29:39 +0000 (11:29 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Dec 2013 14:42:11 +0000 (15:42 +0100)
Use a temporary output buffer to ensure we don't affect the output
on failure of inet_pton().

src/standard.c

index ebbc70c6221e579ba2f0c81fa571023e3cc07035..72fd0d6d427f8e1c9bc13387e27e7babfd13c22e 100644 (file)
@@ -1644,6 +1644,7 @@ unsigned int inetaddr_host_lim_ret(char *text, char *stop, char **ret)
  * or the number of chars read in case of success. Maybe this could be replaced
  * by one of the functions above. Also, apparently this function does not support
  * hosts above 255 and requires exactly 4 octets.
+ * The destination is only modified on success.
  */
 int buf2ip(const char *buf, size_t len, struct in_addr *dst)
 {
@@ -1695,10 +1696,12 @@ int buf2ip(const char *buf, size_t len, struct in_addr *dst)
 /* This function converts the string in <buf> of the len <len> to
  * struct in6_addr <dst> which must be allocated by the caller.
  * This function returns 1 in success case, otherwise zero.
+ * The destination is only modified on success.
  */
 int buf2ip6(const char *buf, size_t len, struct in6_addr *dst)
 {
        char null_term_ip6[INET6_ADDRSTRLEN + 1];
+       struct in6_addr out;
 
        if (len > INET6_ADDRSTRLEN)
                return 0;
@@ -1706,9 +1709,10 @@ int buf2ip6(const char *buf, size_t len, struct in6_addr *dst)
        memcpy(null_term_ip6, buf, len);
        null_term_ip6[len] = '\0';
 
-       if (!inet_pton(AF_INET6, null_term_ip6, dst))
+       if (!inet_pton(AF_INET6, null_term_ip6, &out))
                return 0;
 
+       *dst = out;
        return 1;
 }