From 6c2ccc947df8eda13c0675f16e640cadc92b7cc3 Mon Sep 17 00:00:00 2001 From: EunBong Song Date: Tue, 4 Jul 2017 13:11:26 +0900 Subject: [PATCH] libc netdb: gethostbyname_r: Fix check for space in buffer. This patch comes from Nuttx commit id: ee7217be Change-Id: Ifc2b1973978b1b16e7fa1795a6009717bd67aa51 Signed-off-by: EunBong Song --- lib/libc/netdb/lib_gethostbyaddrr.c | 2 +- lib/libc/netdb/lib_gethostbynamer.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libc/netdb/lib_gethostbyaddrr.c b/lib/libc/netdb/lib_gethostbyaddrr.c index 6c08e22..a2653ef 100644 --- a/lib/libc/netdb/lib_gethostbyaddrr.c +++ b/lib/libc/netdb/lib_gethostbyaddrr.c @@ -213,7 +213,7 @@ static int lib_localhost(FAR const void *addr, socklen_t len, int type, FAR stru /* And copy localhost host name */ namelen = strlen(g_lo_hostname); - if (addrlen + namelen + 1 > buflen) { + if ((namelen + 1) > buflen) { herrnocode = ERANGE; goto errorout_with_herrnocode; } diff --git a/lib/libc/netdb/lib_gethostbynamer.c b/lib/libc/netdb/lib_gethostbynamer.c index d23649d..3928b7d 100644 --- a/lib/libc/netdb/lib_gethostbynamer.c +++ b/lib/libc/netdb/lib_gethostbynamer.c @@ -215,7 +215,7 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host, F /* And copy name */ namelen = strlen(name); - if (addrlen + namelen + 1 > buflen) { + if ((namelen + 1) > buflen) { return -ERANGE; } @@ -403,7 +403,7 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, FAR c /* And copy the host name */ namelen = strlen(name); - if (addrlen + namelen + 1 > buflen) { + if ((namelen + 1) > buflen) { return -ERANGE; } @@ -539,7 +539,7 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, FAR ch /* And copy name */ namelen = strlen(name); - if (addrlen + namelen + 1 > buflen) { + if ((namelen + 1) > buflen) { return -ERANGE; } -- 2.7.4