diff options
author | Robert Ransom <rransom.8774@gmail.com> | 2011-06-02 02:24:18 -0700 |
---|---|---|
committer | Robert Ransom <rransom.8774@gmail.com> | 2011-06-02 02:52:40 -0700 |
commit | a1d866edc9af82c2134590f7ee3c4e18156a655c (patch) | |
tree | 4facc7a7e2164fafec3359ab0f64f187fd8513e1 | |
parent | 1d8bcba067ef8d96ebe022f06459d55c308343ec (diff) | |
download | tor-a1d866edc9af82c2134590f7ee3c4e18156a655c.tar.gz tor-a1d866edc9af82c2134590f7ee3c4e18156a655c.zip |
Make last_hid_serv_requests functions less fragile
Previously, Tor would dereference a NULL pointer and crash if
lookup_last_hid_serv_request were called before the first call to
directory_clean_last_hid_serv_requests. As far as I can tell, that's
currently impossible, but I want that undocumented invariant to go away
in case I^Wwe break it someday.
-rw-r--r-- | src/or/rendclient.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/or/rendclient.c b/src/or/rendclient.c index 29b9d260ed..ec6e3f2bed 100644 --- a/src/or/rendclient.c +++ b/src/or/rendclient.c @@ -377,7 +377,17 @@ rend_client_introduction_acked(origin_circuit_t *circ, * certain queries; keys are strings consisting of base32-encoded * hidden service directory identities and base32-encoded descriptor IDs; * values are pointers to timestamps of the last requests. */ -static strmap_t *last_hid_serv_requests = NULL; +static strmap_t *last_hid_serv_requests_ = NULL; + +/** Returns last_hid_serv_requests_, initializing it to a new strmap if + * necessary. */ +static strmap_t * +get_last_hid_serv_requests(void) +{ + if (!last_hid_serv_requests_) + last_hid_serv_requests_ = strmap_new(); + return last_hid_serv_requests_; +} /** Look up the last request time to hidden service directory <b>hs_dir</b> * for descriptor ID <b>desc_id_base32</b>. If <b>set</b> is non-zero, @@ -391,6 +401,7 @@ lookup_last_hid_serv_request(routerstatus_t *hs_dir, char hsdir_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1]; char hsdir_desc_comb_id[2 * REND_DESC_ID_V2_LEN_BASE32 + 1]; time_t *last_request_ptr; + strmap_t *last_hid_serv_requests = get_last_hid_serv_requests(); base32_encode(hsdir_id_base32, sizeof(hsdir_id_base32), hs_dir->identity_digest, DIGEST_LEN); tor_snprintf(hsdir_desc_comb_id, sizeof(hsdir_desc_comb_id), "%s%s", @@ -416,8 +427,7 @@ directory_clean_last_hid_serv_requests(void) { strmap_iter_t *iter; time_t cutoff = time(NULL) - REND_HID_SERV_DIR_REQUERY_PERIOD; - if (!last_hid_serv_requests) - last_hid_serv_requests = strmap_new(); + strmap_t *last_hid_serv_requests = get_last_hid_serv_requests(); for (iter = strmap_iter_init(last_hid_serv_requests); !strmap_iter_done(iter); ) { const char *key; |