aboutsummaryrefslogtreecommitdiff
path: root/src/or/dirvote.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-10-09 19:31:14 +0000
committerNick Mathewson <nickm@torproject.org>2007-10-09 19:31:14 +0000
commit0827d6f217797b2b70834e85cf8d05d8c72dc28a (patch)
treefb5d7b2a6a7ce690ba0d2a55e832202c4a2d73e8 /src/or/dirvote.c
parenta2005cd2c128a73ac7e41667820353687f9b2667 (diff)
downloadtor-0827d6f217797b2b70834e85cf8d05d8c72dc28a.tar.gz
tor-0827d6f217797b2b70834e85cf8d05d8c72dc28a.zip
r15593@catbus: nickm | 2007-10-09 15:31:10 -0400
Fix an infinite loop when parsing multiple votes. svn:r11813
Diffstat (limited to 'src/or/dirvote.c')
-rw-r--r--src/or/dirvote.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index 6a96eb91fe..40a964a3a3 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -1359,6 +1359,8 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
again:
vote = networkstatus_parse_vote_from_string(vote_body, &end_of_vote, 1);
+ if (!end_of_vote)
+ end_of_vote = vote_body + strlen(vote_body);
if (!vote) {
log_warn(LD_DIR, "Couldn't parse vote: length was %d",
(int)strlen(vote_body));
@@ -1424,7 +1426,8 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
"directory.");
cached_dir_decref(v->vote_body);
networkstatus_vote_free(v->vote);
- v->vote_body = new_cached_dir(tor_strdup(vote_body),
+ v->vote_body = new_cached_dir(tor_strndup(vote_body,
+ end_of_vote-vote_body),
vote->published);
v->vote = vote;
if (end_of_vote &&
@@ -1444,13 +1447,16 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
});
pending_vote = tor_malloc_zero(sizeof(pending_vote_t));
- pending_vote->vote_body = new_cached_dir(tor_strdup(vote_body),
+ pending_vote->vote_body = new_cached_dir(tor_strndup(vote_body,
+ end_of_vote-vote_body),
vote->published);
pending_vote->vote = vote;
smartlist_add(pending_vote_list, pending_vote);
- if (end_of_vote && !strcmpstart(end_of_vote, "network-status-version "))
+ if (!strcmpstart(end_of_vote, "network-status-version ")) {
+ vote_body = end_of_vote;
goto again;
+ }
goto done;
@@ -1465,8 +1471,10 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
if (vote)
networkstatus_vote_free(vote);
- if (end_of_vote && !strcmpstart(end_of_vote, "network-status-version "))
+ if (end_of_vote && !strcmpstart(end_of_vote, "network-status-version ")) {
+ vote_body = end_of_vote;
goto again;
+ }
done: