Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Goulet
Tor
Commits
f0260c4c
Commit
f0260c4c
authored
Apr 23, 2021
by
George Kadianakis
Browse files
Merge branch 'maint-0.4.5' into maint-0.4.6
parents
38bfb3cd
8c297299
Changes
2
Hide whitespace changes
Inline
Side-by-side
changes/ticket40356
0 → 100644
View file @
f0260c4c
o Minor bugfix (onion service, client, memory leak):
- An expired cached descriptor could have been overwritten with a new one
leading to a memory leak. Fixes bug 40356; bugfix on 0.3.5.1-alpha.
src/feature/hs/hs_cache.c
View file @
f0260c4c
...
@@ -353,6 +353,31 @@ static digest256map_t *hs_cache_v3_client;
...
@@ -353,6 +353,31 @@ static digest256map_t *hs_cache_v3_client;
* objects all related to a specific service. */
* objects all related to a specific service. */
static
digest256map_t
*
hs_cache_client_intro_state
;
static
digest256map_t
*
hs_cache_client_intro_state
;
#define cache_client_desc_free(val) \
FREE_AND_NULL(hs_cache_client_descriptor_t, cache_client_desc_free_, (val))
/** Free memory allocated by <b>desc</b>. */
static
void
cache_client_desc_free_
(
hs_cache_client_descriptor_t
*
desc
)
{
if
(
desc
==
NULL
)
{
return
;
}
hs_descriptor_free
(
desc
->
desc
);
memwipe
(
&
desc
->
key
,
0
,
sizeof
(
desc
->
key
));
memwipe
(
desc
->
encoded_desc
,
0
,
strlen
(
desc
->
encoded_desc
));
tor_free
(
desc
->
encoded_desc
);
tor_free
(
desc
);
}
/** Helper function: Use by the free all function to clear the client cache */
static
void
cache_client_desc_free_void
(
void
*
ptr
)
{
hs_cache_client_descriptor_t
*
desc
=
ptr
;
cache_client_desc_free
(
desc
);
}
/** Return the size of a client cache entry in bytes. */
/** Return the size of a client cache entry in bytes. */
static
size_t
static
size_t
cache_get_client_entry_size
(
const
hs_cache_client_descriptor_t
*
entry
)
cache_get_client_entry_size
(
const
hs_cache_client_descriptor_t
*
entry
)
...
@@ -390,7 +415,18 @@ remove_v3_desc_as_client(const hs_cache_client_descriptor_t *desc)
...
@@ -390,7 +415,18 @@ remove_v3_desc_as_client(const hs_cache_client_descriptor_t *desc)
static
void
static
void
store_v3_desc_as_client
(
hs_cache_client_descriptor_t
*
desc
)
store_v3_desc_as_client
(
hs_cache_client_descriptor_t
*
desc
)
{
{
hs_cache_client_descriptor_t
*
cached_desc
;
tor_assert
(
desc
);
tor_assert
(
desc
);
/* Because the lookup function doesn't return an expired entry, it can linger
* in the cache until we clean it up or a new descriptor is stored. So,
* before adding, we'll make sure we are not overwriting an old descriptor
* (which is OK in terms of semantic) but leads to memory leak. */
cached_desc
=
digest256map_get
(
hs_cache_v3_client
,
desc
->
key
.
pubkey
);
if
(
cached_desc
)
{
cache_client_desc_free
(
cached_desc
);
}
digest256map_set
(
hs_cache_v3_client
,
desc
->
key
.
pubkey
,
desc
);
digest256map_set
(
hs_cache_v3_client
,
desc
->
key
.
pubkey
,
desc
);
/* Update cache size with this entry for the OOM handler. */
/* Update cache size with this entry for the OOM handler. */
hs_cache_increment_allocation
(
cache_get_client_entry_size
(
desc
));
hs_cache_increment_allocation
(
cache_get_client_entry_size
(
desc
));
...
@@ -473,31 +509,6 @@ cache_client_desc_new(const char *desc_str,
...
@@ -473,31 +509,6 @@ cache_client_desc_new(const char *desc_str,
return
client_desc
;
return
client_desc
;
}
}
#define cache_client_desc_free(val) \
FREE_AND_NULL(hs_cache_client_descriptor_t, cache_client_desc_free_, (val))
/** Free memory allocated by <b>desc</b>. */
static
void
cache_client_desc_free_
(
hs_cache_client_descriptor_t
*
desc
)
{
if
(
desc
==
NULL
)
{
return
;
}
hs_descriptor_free
(
desc
->
desc
);
memwipe
(
&
desc
->
key
,
0
,
sizeof
(
desc
->
key
));
memwipe
(
desc
->
encoded_desc
,
0
,
strlen
(
desc
->
encoded_desc
));
tor_free
(
desc
->
encoded_desc
);
tor_free
(
desc
);
}
/** Helper function: Use by the free all function to clear the client cache */
static
void
cache_client_desc_free_void
(
void
*
ptr
)
{
hs_cache_client_descriptor_t
*
desc
=
ptr
;
cache_client_desc_free
(
desc
);
}
/** Return a newly allocated and initialized hs_cache_intro_state_t object. */
/** Return a newly allocated and initialized hs_cache_intro_state_t object. */
static
hs_cache_intro_state_t
*
static
hs_cache_intro_state_t
*
cache_intro_state_new
(
void
)
cache_intro_state_new
(
void
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment