From ee7217be63856fc6b5582ae93fe9768b49833642 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 12 Jun 2017 06:47:43 -0600 Subject: [PATCH] gethostbyname_r: Fix check for space in buffer. --- libc/netdb/lib_gethostbynamer.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index 96fcf9312c..8ad93ac6f3 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -196,12 +196,10 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host, ptr += addrlen; buflen -= addrlen; - /* And copy name - * REVISIT: Should the check not be (namelen + 1 > buflen)? - */ + /* And copy name */ namelen = strlen(name); - if (addrlen + namelen + 1 > buflen) + if ((namelen + 1) > buflen) { return -ERANGE; } @@ -286,12 +284,10 @@ static int lib_localhost(FAR const char *name, FAR struct hostent *host, dest += addrlen; buflen -= addrlen; - /* And copy name - * REVISIT: Should the check not be (namelen + 1 > buflen)? - */ + /* And copy name */ namelen = strlen(name); - if (addrlen + namelen + 1 > buflen) + if ((namelen + 1) > buflen) { return -ERANGE; } @@ -404,12 +400,10 @@ static int lib_find_answer(FAR const char *name, FAR struct hostent *host, ptr += addrlen; buflen -= addrlen; - /* And copy name - * REVISIT: Should the check not be (namelen + 1 > buflen)? - */ + /* And copy name */ namelen = strlen(name); - if (addrlen + namelen + 1 > buflen) + if ((namelen + 1) > buflen) { return -ERANGE; } @@ -552,12 +546,10 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host, ptr += addrlen; buflen -= addrlen; - /* And copy name - * REVISIT: Should the check not be (namelen + 1 > buflen)? - */ + /* And copy name */ namelen = strlen(name); - if (addrlen + namelen + 1 > buflen) + if ((namelen + 1) > buflen) { return -ERANGE; }