prop224: Use a const pointer for the cache lookup entry

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet 2016-09-15 14:13:18 -04:00
parent 1263f74a12
commit 3f29688bdf
4 changed files with 12 additions and 17 deletions

View File

@ -3400,7 +3400,7 @@ handle_get_hs_descriptor_v3(dir_connection_t *conn,
const get_handler_args_t *args) const get_handler_args_t *args)
{ {
int retval; int retval;
char *desc_str = NULL; const char *desc_str = NULL;
const char *pubkey_str = NULL; const char *pubkey_str = NULL;
const char *url = args->url; const char *url = args->url;
@ -3434,8 +3434,6 @@ handle_get_hs_descriptor_v3(dir_connection_t *conn,
connection_write_to_buf(desc_str, strlen(desc_str), TO_CONN(conn)); connection_write_to_buf(desc_str, strlen(desc_str), TO_CONN(conn));
done: done:
tor_free(desc_str);
return 0; return 0;
} }

View File

@ -142,13 +142,13 @@ cache_store_v3_as_dir(hs_cache_dir_descriptor_t *desc)
return -1; return -1;
} }
/* Using the query which is the blinded key for a descriptor version 3, lookup /* Using the query which is the base64 encoded blinded key of a version 3
* in our directory cache the entry. If found, 1 is returned and desc_out is * descriptor, lookup in our directory cache the entry. If found, 1 is
* populated with a newly allocated string being the encoded descriptor. If * returned and desc_out is populated with a newly allocated string being the
* not found, 0 is returned and desc_out is untouched. On error, a negative * encoded descriptor. If not found, 0 is returned and desc_out is untouched.
* value is returned and desc_out is untouched. */ * On error, a negative value is returned and desc_out is untouched. */
static int static int
cache_lookup_v3_as_dir(const char *query, char **desc_out) cache_lookup_v3_as_dir(const char *query, const char **desc_out)
{ {
int found = 0; int found = 0;
ed25519_public_key_t blinded_key; ed25519_public_key_t blinded_key;
@ -167,7 +167,7 @@ cache_lookup_v3_as_dir(const char *query, char **desc_out)
if (entry != NULL) { if (entry != NULL) {
found = 1; found = 1;
if (desc_out) { if (desc_out) {
*desc_out = tor_strdup(entry->encoded_desc); *desc_out = entry->encoded_desc;
} }
} }
@ -270,7 +270,7 @@ hs_cache_store_as_dir(const char *desc)
* untouched. */ * untouched. */
int int
hs_cache_lookup_as_dir(uint32_t version, const char *query, hs_cache_lookup_as_dir(uint32_t version, const char *query,
char **desc_out) const char **desc_out)
{ {
int found; int found;

View File

@ -48,7 +48,7 @@ size_t hs_cache_handle_oom(time_t now, size_t min_remove_bytes);
* right function. */ * right function. */
int hs_cache_store_as_dir(const char *desc); int hs_cache_store_as_dir(const char *desc);
int hs_cache_lookup_as_dir(uint32_t version, const char *query, int hs_cache_lookup_as_dir(uint32_t version, const char *query,
char **desc_out); const char **desc_out);
#ifdef HS_CACHE_PRIVATE #ifdef HS_CACHE_PRIVATE

View File

@ -131,7 +131,8 @@ test_directory(void *arg)
{ {
int ret; int ret;
size_t oom_size; size_t oom_size;
char *desc_out, *desc1_str; char *desc1_str;
const char *desc_out;
hs_descriptor_t *desc1; hs_descriptor_t *desc1;
(void) arg; (void) arg;
@ -158,7 +159,6 @@ test_directory(void *arg)
ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out); ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
tt_int_op(ret, OP_EQ, 1); tt_int_op(ret, OP_EQ, 1);
tt_str_op(desc_out, OP_EQ, desc1_str); tt_str_op(desc_out, OP_EQ, desc1_str);
tor_free(desc_out);
/* Tell our OOM to run and to at least remove a byte which will result in /* Tell our OOM to run and to at least remove a byte which will result in
* removing the descriptor from our cache. */ * removing the descriptor from our cache. */
oom_size = hs_cache_handle_oom(time(NULL), 1); oom_size = hs_cache_handle_oom(time(NULL), 1);
@ -186,7 +186,6 @@ test_directory(void *arg)
ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out); ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
tt_int_op(ret, OP_EQ, 1); tt_int_op(ret, OP_EQ, 1);
tt_str_op(desc_out, OP_EQ, desc1_str); tt_str_op(desc_out, OP_EQ, desc1_str);
tor_free(desc_out);
/* We should NOT find our zero lifetime desc in our cache. */ /* We should NOT find our zero lifetime desc in our cache. */
ret = hs_cache_lookup_as_dir(3, ret = hs_cache_lookup_as_dir(3,
helper_get_hsdir_query(desc_zero_lifetime), helper_get_hsdir_query(desc_zero_lifetime),
@ -221,7 +220,6 @@ test_directory(void *arg)
tt_int_op(ret, OP_EQ, 0); tt_int_op(ret, OP_EQ, 0);
ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out); ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
tt_int_op(ret, OP_EQ, 1); tt_int_op(ret, OP_EQ, 1);
tor_free(desc_out);
/* Bump revision counter. */ /* Bump revision counter. */
desc1->plaintext_data.revision_counter++; desc1->plaintext_data.revision_counter++;
ret = hs_desc_encode_descriptor(desc1, &new_desc_str); ret = hs_desc_encode_descriptor(desc1, &new_desc_str);
@ -232,7 +230,6 @@ test_directory(void *arg)
ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out); ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
tt_int_op(ret, OP_EQ, 1); tt_int_op(ret, OP_EQ, 1);
tt_str_op(desc_out, OP_EQ, new_desc_str); tt_str_op(desc_out, OP_EQ, new_desc_str);
tor_free(desc_out);
tor_free(new_desc_str); tor_free(new_desc_str);
} }