diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-12-18 21:32:53 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-12-18 21:32:53 -0500 |
commit | 8b5787ec0d99a130ead302f7c6b4a256325ac08f (patch) | |
tree | ebbd942c9dcbc65d91a443f27810991ca9d118cb /src/or/routerlist.c | |
parent | 7a99d26c798a2223c8277e6c358eb76195d18dab (diff) | |
download | tor-8b5787ec0d99a130ead302f7c6b4a256325ac08f.tar.gz tor-8b5787ec0d99a130ead302f7c6b4a256325ac08f.zip |
When there are no dir_server_ts to choose, don't crash
It's important not to call choose_array_element_by_weight and then
pass its return value unchecked to smartlist_get : it is allowed to
return -1.
Fixes bug 7756; bugfix on 4e3d07a6 (not in any released Tor)
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r-- | src/or/routerlist.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 972d4513dd..898b9b5b98 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1270,7 +1270,7 @@ dirserver_choose_by_weight(const smartlist_t *servers, double authority_weight) scale_array_elements_to_u64(weights, n, NULL); i = choose_array_element_by_weight(weights, n); tor_free(weights); - return smartlist_get(servers, i); + return (i < 0) ? NULL : smartlist_get(servers, i); } /** Choose randomly from among the dir_server_ts in sourcelist that |