[v2,2/3] inet: Remove strdupa from nrl_domainname()

Message ID 20211210110733.1499984-3-adhemerval.zanella@linaro.org
State Committed
Commit b3c68b10afddf160c09c6862341b7fcfcaac901c
Headers
Series Fixes for getnameinfo() with NI_NOFQDN |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Dec. 10, 2021, 11:07 a.m. UTC
  We can use the already in place scratch_buffer.

Checked on x86_64-linux-gnu.
---
 inet/getnameinfo.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
  

Comments

Adhemerval Zanella Feb. 3, 2022, 8:52 p.m. UTC | #1
Ping.

On 10/12/2021 08:07, Adhemerval Zanella wrote:
> We can use the already in place scratch_buffer.
> 
> Checked on x86_64-linux-gnu.
> ---
>  inet/getnameinfo.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/inet/getnameinfo.c b/inet/getnameinfo.c
> index 5eee354200..2d2397e7dc 100644
> --- a/inet/getnameinfo.c
> +++ b/inet/getnameinfo.c
> @@ -118,15 +118,15 @@ nrl_domainname_core (struct scratch_buffer *tmpbuf)
>        else
>  	{
>  	  /* We need to preserve the hostname.  */
> -	  const char *hstname = strdupa (tmpbuf->data);
> -	  while (__gethostbyname_r (hstname, &th,
> -				    tmpbuf->data,
> -				    tmpbuf->length,
> +	  size_t hstnamelen = strlen (tmpbuf->data) + 1;
> +	  while (__gethostbyname_r (tmpbuf->data, &th,
> +				    tmpbuf->data + hstnamelen,
> +				    tmpbuf->length - hstnamelen,
>  				    &h, &herror))
>  	    {
>  	      if (herror == NETDB_INTERNAL && errno == ERANGE)
>  		{
> -		  if (!scratch_buffer_grow (tmpbuf))
> +		  if (!scratch_buffer_grow_preserve (tmpbuf))
>  		    return;
>  		}
>  	      else
  

Patch

diff --git a/inet/getnameinfo.c b/inet/getnameinfo.c
index 5eee354200..2d2397e7dc 100644
--- a/inet/getnameinfo.c
+++ b/inet/getnameinfo.c
@@ -118,15 +118,15 @@  nrl_domainname_core (struct scratch_buffer *tmpbuf)
       else
 	{
 	  /* We need to preserve the hostname.  */
-	  const char *hstname = strdupa (tmpbuf->data);
-	  while (__gethostbyname_r (hstname, &th,
-				    tmpbuf->data,
-				    tmpbuf->length,
+	  size_t hstnamelen = strlen (tmpbuf->data) + 1;
+	  while (__gethostbyname_r (tmpbuf->data, &th,
+				    tmpbuf->data + hstnamelen,
+				    tmpbuf->length - hstnamelen,
 				    &h, &herror))
 	    {
 	      if (herror == NETDB_INTERNAL && errno == ERANGE)
 		{
-		  if (!scratch_buffer_grow (tmpbuf))
+		  if (!scratch_buffer_grow_preserve (tmpbuf))
 		    return;
 		}
 	      else