Ticket #22789: 0001-Fix-assertion-failure-related-to-openbsd-strtol.patch

File 0001-Fix-assertion-failure-related-to-openbsd-strtol.patch, 2.2 KB (added by nickm, 7 weeks ago)
  • new file changes/bug22789

    From bb3f74e66bd9df94ce9d1949164348efac728ea9 Mon Sep 17 00:00:00 2001
    From: Nick Mathewson <nickm@torproject.org>
    Date: Mon, 3 Jul 2017 11:20:09 -0400
    Subject: [PATCH] Fix assertion failure related to openbsd strtol().
    
    Fixes bug 22789; bugfix on 0.2.3.8-alpha.
    ---
     changes/bug22789     | 6 ++++++
     src/common/compat.c  | 8 ++++++--
     src/test/test_addr.c | 9 +++++++++
     3 files changed, 21 insertions(+), 2 deletions(-)
     create mode 100644 changes/bug22789
    
    diff --git a/changes/bug22789 b/changes/bug22789
    new file mode 100644
    index 00000000000000..dc9fa298112620
    - +  
     1  o Major bugfixes (openbsd, denial-of-service):
     2    - Avoid an assertion failure bug affecting our implementation of
     3      inet_pton(AF_INET6) on certain OpenBSD systems whose strtol()
     4      handling of "0xfoo" differs from what we had expected.
     5      Fixes bug 22789; bugfix on 0.2.3.8-alpha.
     6
  • src/common/compat.c

    diff --git a/src/common/compat.c b/src/common/compat.c
    index d88c5f92dec40a..b77f25b4677e65 100644
    a b tor_inet_pton(int af, const char *src, void *dst) 
    20452045        char *next;
    20462046        ssize_t len;
    20472047        long r = strtol(src, &next, 16);
    2048         tor_assert(next != NULL);
    2049         tor_assert(next != src);
     2048        if (next == NULL || next == src) {
     2049          /* The 'next == src' error case can happen on versions of openbsd
     2050           * where treats "0xfoo" as an error, rather than as "0" followed by
     2051           * "xfoo". */
     2052          return 0;
     2053        }
    20502054
    20512055        len = *next == '\0' ? eow - src : next - src;
    20522056        if (len > 4)
  • src/test/test_addr.c

    diff --git a/src/test/test_addr.c b/src/test/test_addr.c
    index fec85a4696497c..645fc643db2ba2 100644
    a b test_addr_ip6_helpers(void) 
    340340  test_pton6_bad("a:::b:c");
    341341  test_pton6_bad(":::a:b:c");
    342342  test_pton6_bad("a:b:c:::");
     343  /* Regression tests for 22789. */
     344  test_pton6_bad("0xfoo");
     345  test_pton6_bad("0x88");
     346  test_pton6_bad("0xyxxy");
     347  test_pton6_bad("0XFOO");
     348  test_pton6_bad("0X88");
     349  test_pton6_bad("0XYXXY");
     350  test_pton6_bad("0x");
     351  test_pton6_bad("0X");
    343352
    344353  /* test internal checking */
    345354  test_external_ip("fbff:ffff::2:7", 0);