[PATCH] ngx_pstrdup() and ngx_copy() problems
Sergey Matveychuk
sem33 at yandex-team.ru
Tue Dec 22 14:21:26 UTC 2015
Hi.
* It looks like strings are supposed to finish with '\0' char to be
compatible with C strings. So ngx_pstrdup() must allocate and copy
len+1, not just len.
* ngx_copy() returns different values for different preprocessor conditions.
PS. I have no idea how trac.nginx.org works. I tried to fill a ticket,
but it just lost.
-------------- next part --------------
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 503502a..77d7c3c 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -58,12 +58,12 @@ ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src)
{
u_char *dst;
- dst = ngx_pnalloc(pool, src->len);
+ dst = ngx_pnalloc(pool, src->len + 1);
if (dst == NULL) {
return NULL;
}
- ngx_memcpy(dst, src->data, src->len);
+ ngx_memcpy(dst, src->data, src->len + 1);
return dst;
}
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index 712e7d0..e0380a9 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -122,7 +122,7 @@ ngx_copy(u_char *dst, u_char *src, size_t len)
len--;
}
- return dst;
+ return dst + len;
} else {
return ngx_cpymem(dst, src, len);
More information about the nginx-devel
mailing list