diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-02-11 08:47:19 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-02-11 08:47:19 -0500 |
commit | 384a771fccb0b0ab8b95122815b33ef26bf042e8 (patch) | |
tree | 53096ec69b66df84f3bac1095193ed3cf2b06acd /src/lib/net | |
parent | d9a70ba21262ee92b53eae791171433e2142a902 (diff) | |
parent | 777d90fa23785b5a9847a6667889a33fafb3a701 (diff) | |
download | tor-384a771fccb0b0ab8b95122815b33ef26bf042e8.tar.gz tor-384a771fccb0b0ab8b95122815b33ef26bf042e8.zip |
Merge branch 'ticket32362_squashed'
Diffstat (limited to 'src/lib/net')
-rw-r--r-- | src/lib/net/.may_include | 3 | ||||
-rw-r--r-- | src/lib/net/inaddr.c | 21 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/lib/net/.may_include b/src/lib/net/.may_include index e4368f799b..6e9af9737a 100644 --- a/src/lib/net/.may_include +++ b/src/lib/net/.may_include @@ -14,4 +14,5 @@ lib/net/*.h lib/string/*.h lib/subsys/*.h lib/testsupport/*.h -lib/malloc/*.h
\ No newline at end of file +lib/malloc/*.h +lib/smartlist_core/*.h diff --git a/src/lib/net/inaddr.c b/src/lib/net/inaddr.c index 0d20d88901..d50ac2440c 100644 --- a/src/lib/net/inaddr.c +++ b/src/lib/net/inaddr.c @@ -11,7 +11,9 @@ #include "lib/net/inaddr.h" #include "lib/cc/torint.h" +#include "lib/container/smartlist.h" #include "lib/log/util_bug.h" +#include "lib/malloc/malloc.h" #include "lib/net/inaddr_st.h" #include "lib/string/compat_ctype.h" #include "lib/string/compat_string.h" @@ -39,8 +41,27 @@ tor_inet_aton(const char *str, struct in_addr *addr) { unsigned a, b, c, d; char more; + bool is_octal = false; + smartlist_t *sl = NULL; + if (tor_sscanf(str, "%3u.%3u.%3u.%3u%c", &a, &b, &c, &d, &more) != 4) return 0; + + /* Parse the octets and check them for leading zeros. */ + sl = smartlist_new(); + smartlist_split_string(sl, str, ".", 0, 0); + SMARTLIST_FOREACH(sl, const char *, octet, { + is_octal = (strlen(octet) > 1 && octet[0] == '0'); + if (is_octal) { + break; + } + }); + SMARTLIST_FOREACH(sl, char *, octet, tor_free(octet)); + smartlist_free(sl); + + if (is_octal) + return 0; + if (a > 255) return 0; if (b > 255) return 0; if (c > 255) return 0; |