From 13083fa6d2130b0e2c4f5bb03c90b99d44564408 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 14 Aug 2012 17:14:04 -0400 Subject: [PATCH] Fix: Possible invalid read on string in set_ip_address() Acked-by: Christian Babeux Signed-off-by: David Goulet --- src/common/uri.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common/uri.c b/src/common/uri.c index 3581e307d..e686f7c5d 100644 --- a/src/common/uri.c +++ b/src/common/uri.c @@ -16,6 +16,7 @@ */ #define _GNU_SOURCE +#include #include #include #include @@ -103,6 +104,11 @@ static int set_ip_address(const char *addr, int af, char *dst, size_t size) unsigned char buf[sizeof(struct in6_addr)]; struct hostent *record; + assert(addr); + assert(dst); + + memset(dst, 0, size); + /* Network protocol */ ret = inet_pton(af, addr, buf); if (ret < 1) { @@ -117,7 +123,10 @@ static int set_ip_address(const char *addr, int af, char *dst, size_t size) /* Translate IP to string */ (void) inet_ntop(af, record->h_addr_list[0], dst, size); } else { - memcpy(dst, addr, size); + if (size > 0) { + strncpy(dst, addr, size); + dst[size - 1] = '\0'; + } } DBG2("IP address resolved to %s", dst); -- 2.34.1