mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
prop224: Use a const pointer for the cache lookup entry
Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
1263f74a12
commit
3f29688bdf
@ -3400,7 +3400,7 @@ handle_get_hs_descriptor_v3(dir_connection_t *conn,
|
||||
const get_handler_args_t *args)
|
||||
{
|
||||
int retval;
|
||||
char *desc_str = NULL;
|
||||
const char *desc_str = NULL;
|
||||
const char *pubkey_str = NULL;
|
||||
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));
|
||||
|
||||
done:
|
||||
tor_free(desc_str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -142,13 +142,13 @@ cache_store_v3_as_dir(hs_cache_dir_descriptor_t *desc)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Using the query which is the blinded key for a descriptor version 3, lookup
|
||||
* in our directory cache the entry. If found, 1 is returned and desc_out is
|
||||
* populated with a newly allocated string being the encoded descriptor. If
|
||||
* not found, 0 is returned and desc_out is untouched. On error, a negative
|
||||
* value is returned and desc_out is untouched. */
|
||||
/* Using the query which is the base64 encoded blinded key of a version 3
|
||||
* descriptor, lookup in our directory cache the entry. If found, 1 is
|
||||
* returned and desc_out is populated with a newly allocated string being the
|
||||
* encoded descriptor. If not found, 0 is returned and desc_out is untouched.
|
||||
* On error, a negative value is returned and desc_out is untouched. */
|
||||
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;
|
||||
ed25519_public_key_t blinded_key;
|
||||
@ -167,7 +167,7 @@ cache_lookup_v3_as_dir(const char *query, char **desc_out)
|
||||
if (entry != NULL) {
|
||||
found = 1;
|
||||
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. */
|
||||
int
|
||||
hs_cache_lookup_as_dir(uint32_t version, const char *query,
|
||||
char **desc_out)
|
||||
const char **desc_out)
|
||||
{
|
||||
int found;
|
||||
|
||||
|
@ -48,7 +48,7 @@ size_t hs_cache_handle_oom(time_t now, size_t min_remove_bytes);
|
||||
* right function. */
|
||||
int hs_cache_store_as_dir(const char *desc);
|
||||
int hs_cache_lookup_as_dir(uint32_t version, const char *query,
|
||||
char **desc_out);
|
||||
const char **desc_out);
|
||||
|
||||
#ifdef HS_CACHE_PRIVATE
|
||||
|
||||
|
@ -131,7 +131,8 @@ test_directory(void *arg)
|
||||
{
|
||||
int ret;
|
||||
size_t oom_size;
|
||||
char *desc_out, *desc1_str;
|
||||
char *desc1_str;
|
||||
const char *desc_out;
|
||||
hs_descriptor_t *desc1;
|
||||
|
||||
(void) arg;
|
||||
@ -158,7 +159,6 @@ test_directory(void *arg)
|
||||
ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
|
||||
tt_int_op(ret, OP_EQ, 1);
|
||||
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
|
||||
* removing the descriptor from our cache. */
|
||||
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);
|
||||
tt_int_op(ret, OP_EQ, 1);
|
||||
tt_str_op(desc_out, OP_EQ, desc1_str);
|
||||
tor_free(desc_out);
|
||||
/* We should NOT find our zero lifetime desc in our cache. */
|
||||
ret = hs_cache_lookup_as_dir(3,
|
||||
helper_get_hsdir_query(desc_zero_lifetime),
|
||||
@ -221,7 +220,6 @@ test_directory(void *arg)
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
|
||||
tt_int_op(ret, OP_EQ, 1);
|
||||
tor_free(desc_out);
|
||||
/* Bump revision counter. */
|
||||
desc1->plaintext_data.revision_counter++;
|
||||
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);
|
||||
tt_int_op(ret, OP_EQ, 1);
|
||||
tt_str_op(desc_out, OP_EQ, new_desc_str);
|
||||
tor_free(desc_out);
|
||||
tor_free(new_desc_str);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user