Fixed 1-byte overflow in safe_append

This commit is contained in:
Thomas Kolb 2016-12-17 01:10:09 +01:00
parent 577dfd9e1a
commit 3820ba88dc

View file

@ -66,10 +66,10 @@ void urlencode(const char *str, char *result) {
char* safe_append(char *target, size_t *targetsize, const char *src) { char* safe_append(char *target, size_t *targetsize, const char *src) {
size_t targetlen = strlen(target); size_t targetlen = strlen(target);
size_t srclen = strlen(src); size_t srclen = strlen(src);
size_t newsize = targetlen + 2*srclen + 1; size_t newsize = 2*targetlen + srclen + 1;
// check if reallocation is necessary // check if reallocation is necessary
if((targetlen + srclen) > *targetsize) { if((targetlen + srclen) >= *targetsize) {
LOG(LVL_DEBUG, "safe_append: reallocating target string: %lu -> %lu characters", *targetsize, newsize); LOG(LVL_DEBUG, "safe_append: reallocating target string: %lu -> %lu characters", *targetsize, newsize);
target = realloc(target, newsize * sizeof(char)); target = realloc(target, newsize * sizeof(char));