mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
bugfixes: smartlist_join_strings2() was underflowing a size_t
if you gave it an empty smartlist; and it wasn't terminating in this case even if you asked it to. this does not appear to be exploitable in any reasonable cases. svn:r4598
This commit is contained in:
parent
b13a9e9070
commit
893652da84
@ -357,6 +357,10 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
|
||||
|
||||
tor_assert(sl);
|
||||
tor_assert(join);
|
||||
|
||||
if (sl->num_used == 0)
|
||||
n = join_len; /* special-case this one, to avoid underflow */
|
||||
|
||||
for (i = 0; i < sl->num_used; ++i) {
|
||||
n += strlen(sl->list[i]);
|
||||
n += join_len;
|
||||
@ -371,6 +375,11 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
|
||||
dst += join_len;
|
||||
}
|
||||
}
|
||||
if (sl->num_used == 0 && terminate) {
|
||||
/* another special case for length == 0 */
|
||||
memcpy(dst, join, join_len);
|
||||
dst += join_len;
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
if (len_out)
|
||||
|
Loading…
Reference in New Issue
Block a user