]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix possible UB in an end-of-string check in get_next_token().
authorNick Mathewson <nickm@torproject.org>
Thu, 25 Oct 2018 13:06:13 +0000 (09:06 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 25 Oct 2018 13:06:13 +0000 (09:06 -0400)
Remember, you can't check to see if there are N bytes left in a
buffer by doing (buf + N < end), since the buf + N computation might
take you off the end of the buffer and result in undefined behavior.

Fixes 28202; bugfix on 0.2.0.3-alpha.

changes/bug28202 [new file with mode: 0644]
src/or/routerparse.c

diff --git a/changes/bug28202 b/changes/bug28202
new file mode 100644 (file)
index 0000000..182daac
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes (C correctness):
+    - Avoid undefined behavior in an end-of-string check when parsing the
+      BEGIN line in a directory object.  Fixes bug 28202; bugfix on
+      0.2.0.3-alpha.
index 521e237be2966778114859a7a7b4e5a92f6b1dd4..063cbbcdafe4e0cc63cbe33325f580c918499672 100644 (file)
@@ -4964,7 +4964,7 @@ get_next_token(memarea_t *area,
     goto check_object;
 
   obstart = *s; /* Set obstart to start of object spec */
-  if (*s+16 >= eol || memchr(*s+11,'\0',eol-*s-16) || /* no short lines, */
+  if (eol - *s <= 16 || memchr(*s+11,'\0',eol-*s-16) || /* no short lines, */
       strcmp_len(eol-5, "-----", 5) ||           /* nuls or invalid endings */
       (eol-*s) > MAX_UNPARSED_OBJECT_SIZE) {     /* name too long */
     RET_ERR("Malformed object: bad begin line");