summaryrefslogtreecommitdiff
path: root/src/or/routerparse.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-10-14 02:26:13 +0000
committerNick Mathewson <nickm@torproject.org>2005-10-14 02:26:13 +0000
commit998cf8d6222607113fbd8fa8563d507a808ee869 (patch)
tree2e3f8dfbf46c60a659b75f715a65b8266f5377a0 /src/or/routerparse.c
parent11b76b9ca5b39eeeb4fcff1593db2efe14cc5827 (diff)
downloadtor-998cf8d6222607113fbd8fa8563d507a808ee869.tar.gz
tor-998cf8d6222607113fbd8fa8563d507a808ee869.zip
Try to extract as many descriptors as possible from truncated http responses. (when DIR_PURPOSE_FETCH_ROUTERDESC)
svn:r5249
Diffstat (limited to 'src/or/routerparse.c')
-rw-r--r--src/or/routerparse.c25
1 files changed, 21 insertions, 4 deletions
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 *<b>s</b> containing a concatenated sequence of router
* descriptors, parses them and stores the result in <b>dest</b>. 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);
}