diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-07-10 12:54:52 +0200 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-07-18 22:57:36 +0400 |
commit | 09de0ff06ef5ebb3b594a42ca8996f92a854078a (patch) | |
tree | 47311adb51e5f571a920a541b87987d7ff60975a /accel-pppd | |
parent | 4925a61bf843462f987def1820a4ad676100d421 (diff) | |
download | accel-ppp-09de0ff06ef5ebb3b594a42ca8996f92a854078a.tar.gz accel-ppp-09de0ff06ef5ebb3b594a42ca8996f92a854078a.zip |
memdbg: Accept short strings in md_strndup()
Don't fail if string to duplicate is shorter than the size parameter
and handle memory allocation failure.
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/memdebug.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/accel-pppd/memdebug.c b/accel-pppd/memdebug.c index 8c3c494f..5629146a 100644 --- a/accel-pppd/memdebug.c +++ b/accel-pppd/memdebug.c @@ -153,10 +153,15 @@ char __export *md_strdup(const char *ptr, const char *fname, int line) char __export *md_strndup(const char *ptr, size_t n, const char *fname, int line) { - struct mem_t *mem = _md_malloc(n + 1, fname, line); - memcpy(mem->data, ptr, n); - mem->data[n] = 0; - return mem->data; + size_t len = strnlen(ptr, n); + char *str = md_malloc(len + 1, fname, line); + + if (str) { + memcpy(str, ptr, len); + str[len] = '\0'; + } + + return str; } static void siginfo(int num) |