commit 384a771fccb0b0ab8b95122815b33ef26bf042e8 Merge: d9a70ba21 777d90fa2 Author: Nick Mathewson nickm@torproject.org Date: Tue Feb 11 08:47:19 2020 -0500
Merge branch 'ticket32362_squashed'
src/lib/net/.may_include | 3 ++- src/lib/net/inaddr.c | 21 +++++++++++++++++++++ src/test/test_addr.c | 31 +++++++++++++++++++++++++------ 3 files changed, 48 insertions(+), 7 deletions(-)
diff --cc src/lib/net/inaddr.c index 0d20d8890,7ae376b11..d50ac2440 --- a/src/lib/net/inaddr.c +++ b/src/lib/net/inaddr.c @@@ -37,10 -39,29 +39,29 @@@ int tor_inet_aton(const char *str, struct in_addr *addr) { - unsigned a,b,c,d; + 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;