From 998cf8d6222607113fbd8fa8563d507a808ee869 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 14 Oct 2005 02:26:13 +0000 Subject: Try to extract as many descriptors as possible from truncated http responses. (when DIR_PURPOSE_FETCH_ROUTERDESC) svn:r5249 --- src/or/routerparse.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/or/routerparse.c') diff --git a/src/or/routerparse.c b/src/or/routerparse.c index b5f1db05d4..721632c1c5 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -636,13 +636,14 @@ check_directory_signature(const char *digest, /** Given a string *s containing a concatenated sequence of router * descriptors, parses them and stores the result in dest. All routers * are marked running and verified. Advances *s to a point immediately - * following the last router entry. Returns 0 on success and -1 on failure. + * following the last router entry. Ignore any trailing router entries that + * are not complete. Returns 0 on success and -1 on failure. */ int router_parse_list_from_string(const char **s, smartlist_t *dest) { routerinfo_t *router; - const char *end; + const char *end, *cp; tor_assert(s); tor_assert(*s); @@ -654,20 +655,36 @@ router_parse_list_from_string(const char **s, smartlist_t *dest) if (strcmpstart(*s, "router ")!=0) break; if ((end = strstr(*s+1, "\nrouter "))) { + cp = end; end++; } else if ((end = strstr(*s+1, "\ndirectory-signature"))) { + cp = end; end++; } else { - end = *s+strlen(*s); + cp = end = *s+strlen(*s); + } + + while (cp > *s && (!*cp || TOR_ISSPACE(*cp))) + --cp; + /* cp now points to the last non-space character in this descriptor. */ + + while (cp > *s && *cp != '\n') + --cp; + /* cp now points to the first \n before the last non-bank line in this + * descriptor */ + + if (strcmpstart(cp, "\n-----END SIGNATURE-----\n")) { + log_fn(LOG_INFO, "Ignoring truncated router descriptor."); + continue; } router = router_parse_entry_from_string(*s, end); + *s = end; if (!router) { log_fn(LOG_WARN, "Error reading router; skipping"); continue; } - smartlist_add(dest, router); } -- cgit v1.2.3-54-g00ecf