diff options
author | Roger Dingledine <arma@torproject.org> | 2005-07-18 23:11:46 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2005-07-18 23:11:46 +0000 |
commit | 893652da84e5a54b10c48d1962b9e7902f794503 (patch) | |
tree | 138170db7c0f1dbde31f8aae5a9218e2edd9324e /src/common/container.c | |
parent | b13a9e90705d4ad1ca10666d0171a9989f291d7a (diff) | |
download | tor-893652da84e5a54b10c48d1962b9e7902f794503.tar.gz tor-893652da84e5a54b10c48d1962b9e7902f794503.zip |
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
Diffstat (limited to 'src/common/container.c')
-rw-r--r-- | src/common/container.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/common/container.c b/src/common/container.c index dea3f71622..01080612c9 100644 --- a/src/common/container.c +++ b/src/common/container.c @@ -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) |