[{"id":1763537,"web_url":"http://patchwork.ozlabs.org/comment/1763537/","msgid":"<426c9fe6-2b88-96c0-2382-651cf30f2db8@linaro.org>","list_archive_url":null,"date":"2017-09-05T17:53:37","subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","submitter":{"id":66065,"url":"http://patchwork.ozlabs.org/api/people/66065/","name":"Adhemerval Zanella Netto","email":"adhemerval.zanella@linaro.org"},"content":"On 04/09/2017 14:31, Florian Weimer wrote:\n> 2017-09-04  Florian Weimer  <fweimer@redhat.com>\n> \n> \t[BZ #18023]\n> \t* nss/nss_files/files-hosts.c (gethostbyname3_multi): Use struct\n> \tscratch_buffer.\n\nLGTM with some nits below.\n\n\n> \n> diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c\n> index 867c10c2ef..c2cd07584c 100644\n> --- a/nss/nss_files/files-hosts.c\n> +++ b/nss/nss_files/files-hosts.c\n> @@ -22,6 +22,7 @@\n>  #include <arpa/nameser.h>\n>  #include <netdb.h>\n>  #include <resolv/resolv-internal.h>\n> +#include <scratch_buffer.h>\n>  \n>  \n>  /* Get implementation for some internal functions.  */\n> @@ -121,15 +122,12 @@ gethostbyname3_multi (FILE * stream, const char *name, int af,\n>  \t\t      int *errnop, int *herrnop, int flags)\n>  {\n>    /* We have to get all host entries from the file.  */\n> -  size_t tmp_buflen = MIN (buflen, 4096);\n> -  char tmp_buffer_stack[tmp_buflen]\n> -    __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));\n\nI can't really tell how important is the alignment of this buffer in particular,\nsince on subsequent 'internal_getent' it does uses a plain char buffer.  Do we\nneed to keep the alignment of this buffer?\n\n> -  char *tmp_buffer = tmp_buffer_stack;\n> +  struct scratch_buffer tmp_buffer;\n> +  scratch_buffer_init (&tmp_buffer);\n>    struct hostent tmp_result_buf;\n>    int naddrs = 1;\n>    int naliases = 0;\n>    char *bufferend;\n> -  bool tmp_buffer_malloced = false;\n>    enum nss_status status;\n>  \n>    while (result->h_aliases[naliases] != NULL)\n> @@ -138,8 +136,8 @@ gethostbyname3_multi (FILE * stream, const char *name, int af,\n>    bufferend = (char *) &result->h_aliases[naliases + 1];\n>  \n>   again:\n> -  while ((status = internal_getent (stream, &tmp_result_buf, tmp_buffer,\n> -\t\t\t\t    tmp_buflen, errnop, herrnop, af,\n> +  while ((status = internal_getent (stream, &tmp_result_buf, tmp_buffer.data,\n> +\t\t\t\t    tmp_buffer.length, errnop, herrnop, af,\n>  \t\t\t\t    flags))\n>  \t == NSS_STATUS_SUCCESS)\n>      {\n> @@ -266,52 +264,18 @@ gethostbyname3_multi (FILE * stream, const char *name, int af,\n>  \n>    if (status == NSS_STATUS_TRYAGAIN)\n>      {\n> -      size_t newsize = 2 * tmp_buflen;\n> -      if (tmp_buffer_malloced)\n> +      if (!scratch_buffer_grow (&tmp_buffer))\n>  \t{\n> -\t  char *newp = realloc (tmp_buffer, newsize);\n> -\t  if (newp != NULL)\n> -\t    {\n> -\t      assert ((((uintptr_t) newp)\n> -\t\t       & (__alignof__ (struct hostent_data) - 1))\n> -\t\t      == 0);\n> -\t      tmp_buffer = newp;\n> -\t      tmp_buflen = newsize;\n> -\t      goto again;\n> -\t    }\n> -\t}\n> -      else if (!__libc_use_alloca (buflen + newsize))\n> -\t{\n> -\t  tmp_buffer = malloc (newsize);\n> -\t  if (tmp_buffer != NULL)\n> -\t    {\n> -\t      assert ((((uintptr_t) tmp_buffer)\n> -\t\t       & (__alignof__ (struct hostent_data) - 1))\n> -\t\t      == 0);\n> -\t      tmp_buffer_malloced = true;\n> -\t      tmp_buflen = newsize;\n> -\t      goto again;\n> -\t    }\n> +\t  *herrnop = NETDB_INTERNAL;\n> +\t  status = NSS_STATUS_TRYAGAIN;\n>  \t}\n>        else\n> -\t{\n> -\t  tmp_buffer\n> -\t    = extend_alloca (tmp_buffer, tmp_buflen,\n> -\t\t\t     newsize\n> -\t\t\t     + __alignof__ (struct hostent_data));\n> -\t  tmp_buffer = (char *) (((uintptr_t) tmp_buffer\n> -\t\t\t\t  + __alignof__ (struct hostent_data)\n> -\t\t\t\t  - 1)\n> -\t\t\t\t & ~(__alignof__ (struct hostent_data)\n> -\t\t\t\t     - 1));\n> -\t  goto again;\n> -\t}\n> +\tgoto again;\n>      }\n>    else\n>      status = NSS_STATUS_SUCCESS;\n>   out:\n> -  if (tmp_buffer_malloced)\n> -    free (tmp_buffer);\n> +  scratch_buffer_free (&tmp_buffer);\n>    return status;\n>  }\n\nI do think this it is easier to read and follow the code *without* the goto,\nsomething like:\n\nscratch_buffer_init (...);\nwhile (1)\n  {\n    while ((status = internal_getent (...)) == NSS_STATUS_SUCCESS)\n      {\n        ...\n      }\n    if (status == NSS_STATUS_TRYAGAIN)\n      if (!scratch_buffer_grow (&tmp_buffer))\n        {\n          *herrnop = NETDB_INTERNAL;\n          status = NSS_STATUS_TRYAGAIN;\n          break;\n        }\n    else\n      status = NSS_STATUS_SUCCESS;\n  }\nscratch_buffer_free (...);","headers":{"Return-Path":"<libc-alpha-return-84199-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84199-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"gSVrC3zL\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmvTy3hVKz9sNc\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 03:53:58 +1000 (AEST)","(qmail 60894 invoked by alias); 5 Sep 2017 17:53:51 -0000","(qmail 60871 invoked by uid 89); 5 Sep 2017 17:53:50 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:to:references:from:message-id:date\n\t:mime-version:in-reply-to:content-type\n\t:content-transfer-encoding; q=dns; s=default; b=mu5mJdB3/I9CGIUA\n\tI2eIRc0b9s1AGkmITfkQGGpNhWkMPyTkwmZef8zihS8mC/wRovJpLzmYFHS+0NX2\n\ttxnzz0pYexmBd583iaehtB/MIVXzc6ChfBoUZIZvPgZ4phCQGpxz00XHxe1Nj+my\n\tAKFGnLnqax/TC+9hzj0YHLyIMn8=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:to:references:from:message-id:date\n\t:mime-version:in-reply-to:content-type\n\t:content-transfer-encoding; s=default; bh=PCJEazfGaO9dD2W5AWpJxT\n\tnN2vM=; b=gSVrC3zL0SnI/N6DA2fdBtPJv5ln3/HvudCwc1Uytgd8XiIqsTUJlX\n\tePvZu7o0QziV6I0otAaZLP0tyLFxw/7FEOEjoxiDBnOjplCYcbl7Y7KVawKd57hH\n\trOWSHYQ8Iwy1mc0TP9JWffZYTFTLLZsMLRq+/PTWDdp401Pvs4V64=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE,\n\tRCVD_IN_SORBS_SPAM,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=","X-HELO":"mail-qk0-f170.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=Qnr0pDEYz0Hlavj8GsBRPT7oMXC5eOM9tUM3HCVov9o=;\n\tb=MQuHBoYCm4iHv/9JJEtejF0zyk1QT0NzLD8xOhjlVK0KuopjS3f4LJS1LkCu63yEb9\n\t3qPr8MwdJ7OvXLsS+esbm2hRddJdverz5C6NkSfK2Yj9S+yxJ+aZ7x2K923w7M2F9A5d\n\tWgynyXXY7gaaWwHSBeu6uA8JjTjaMK4rW6OXQHyj0JSvCqjhgcx662tpJM9CuUkn1gvV\n\t12tdMSbN8IJyg63wi3jmMy4OD8wHEVj3f+Vw8ZUKZBnMLwv2T9bEJSok1IPocthpOgD6\n\tusi0uabL76PVMw+EmehPs4F/i2DcwoFtKHtvx3txvL6WFYQUYxjeu9QBLaWLWVL4KvgM\n\tp13g==","X-Gm-Message-State":"AHPjjUicNS7e1oc/wYAnK2sGgguyQdS2adZmKMFvySwRYjzfyCk7F9Ae\n\tfVwMFPfKxXidtE4aNFyukw==","X-Google-Smtp-Source":"ADKCNb6U7Lm1X3cJLsQmoVOfJYYan78RchNkchmLuPPM9lHThaGAdC/nOQPiHk0UfsLXxBUY970y7A==","X-Received":"by 10.233.237.202 with SMTP id\n\tc193mr6063709qkg.290.1504634022519; \n\tTue, 05 Sep 2017 10:53:42 -0700 (PDT)","Subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","To":"libc-alpha@sourceware.org","References":"<20170904173123.9C550439942E3@oldenburg.str.redhat.com>","From":"Adhemerval Zanella <adhemerval.zanella@linaro.org>","Message-ID":"<426c9fe6-2b88-96c0-2382-651cf30f2db8@linaro.org>","Date":"Tue, 5 Sep 2017 14:53:37 -0300","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<20170904173123.9C550439942E3@oldenburg.str.redhat.com>","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"7bit"}},{"id":1763560,"web_url":"http://patchwork.ozlabs.org/comment/1763560/","msgid":"<81d77843-06c8-ec51-23b1-542a90d5af4e@redhat.com>","list_archive_url":null,"date":"2017-09-05T18:38:15","subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","submitter":{"id":14312,"url":"http://patchwork.ozlabs.org/api/people/14312/","name":"Florian Weimer","email":"fweimer@redhat.com"},"content":"On 09/05/2017 07:53 PM, Adhemerval Zanella wrote:\n\n>>  /* Get implementation for some internal functions.  */\n>> @@ -121,15 +122,12 @@ gethostbyname3_multi (FILE * stream, const char *name, int af,\n>>  \t\t      int *errnop, int *herrnop, int flags)\n>>  {\n>>    /* We have to get all host entries from the file.  */\n>> -  size_t tmp_buflen = MIN (buflen, 4096);\n>> -  char tmp_buffer_stack[tmp_buflen]\n>> -    __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));\n> \n> I can't really tell how important is the alignment of this buffer in particular,\n> since on subsequent 'internal_getent' it does uses a plain char buffer.  Do we\n> need to keep the alignment of this buffer?\n\ninternal_getent must align on its own because it is called with user\nbuffers and POSIX doesn't say anything about the alignment.\n\nBut struct scratch_buffer supplies max_align_t alignment anyway, which\nis at least the alignment of struct hostent_data (by definition).\n\n> I do think this it is easier to read and follow the code *without* the goto,\n> something like:\n> \n> scratch_buffer_init (...);\n> while (1)\n>   {\n>     while ((status = internal_getent (...)) == NSS_STATUS_SUCCESS)\n>       {\n>         ...\n>       }\n>     if (status == NSS_STATUS_TRYAGAIN)\n>       if (!scratch_buffer_grow (&tmp_buffer))\n>         {\n>           *herrnop = NETDB_INTERNAL;\n>           status = NSS_STATUS_TRYAGAIN;\n>           break;\n>         }\n>     else\n>       status = NSS_STATUS_SUCCESS;\n>   }\n> scratch_buffer_free (...);\n\nRight, I think I'll make this change in the first (refactoring) patch.\n\nThanks,\nFlorian","headers":{"Return-Path":"<libc-alpha-return-84204-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84204-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"uJX0X5Y7\"; dkim-atps=neutral","sourceware.org; auth=none","ext-mx03.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx03.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=fweimer@redhat.com"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmwTM3jC5z9sPr\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 04:38:31 +1000 (AEST)","(qmail 76517 invoked by alias); 5 Sep 2017 18:38:24 -0000","(qmail 75739 invoked by uid 89); 5 Sep 2017 18:38:23 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:to:references:from:message-id:date\n\t:mime-version:in-reply-to:content-type\n\t:content-transfer-encoding; q=dns; s=default; b=qSdcGwRGvX5TiZVx\n\tadeoT3nTaQnmRMFOFl1hjb/Yuf8c8tURU+tkEQ8lHs1UaX1LOFfJ80SnGueZ/UP9\n\t4DFbmWhx5tpqrkH7YIiMrHw6we7HtFtO1XUYFL28ppVD1qaJ0WZk8DgEd/whGH68\n\tCcGlaRCs2xUWzPSp2FU3LyoO0Jw=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:to:references:from:message-id:date\n\t:mime-version:in-reply-to:content-type\n\t:content-transfer-encoding; s=default; bh=yjlb40OfnIUSL0juAczj8O\n\tCO8fA=; b=uJX0X5Y7VAa/CWHt+nbRj/nntaZlSHe/NxqJazP1sddYLQnfgTAE9t\n\tf7OY7GC4Y9cs9Kxmy8GOqO2aTX/o0nMk9Je+cg+I0KcxMFXrO+Ms+0a9XCxWqiJN\n\tjJvxz6ow4nznZDGESz0N8U2TSiKGCLRdpZuRqSoV3cvorIW0LFlyk=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-0.9 required=5.0 tests=BAYES_00,\n\tKAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD,\n\tSPF_HELO_PASS autolearn=no version=3.3.2 spammy=","X-HELO":"mx1.redhat.com","DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com C295D78EA2","Subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","To":"Adhemerval Zanella <adhemerval.zanella@linaro.org>,\n\tlibc-alpha@sourceware.org","References":"<20170904173123.9C550439942E3@oldenburg.str.redhat.com>\n\t<426c9fe6-2b88-96c0-2382-651cf30f2db8@linaro.org>","From":"Florian Weimer <fweimer@redhat.com>","Message-ID":"<81d77843-06c8-ec51-23b1-542a90d5af4e@redhat.com>","Date":"Tue, 5 Sep 2017 20:38:15 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<426c9fe6-2b88-96c0-2382-651cf30f2db8@linaro.org>","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"7bit"}},{"id":1783707,"web_url":"http://patchwork.ozlabs.org/comment/1783707/","msgid":"<864301dd-4e83-30ec-d690-b2dbaa3864dc@redhat.com>","list_archive_url":null,"date":"2017-10-10T13:01:58","subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","submitter":{"id":14312,"url":"http://patchwork.ozlabs.org/api/people/14312/","name":"Florian Weimer","email":"fweimer@redhat.com"},"content":"On 09/05/2017 08:38 PM, Florian Weimer wrote:\n\n>> I do think this it is easier to read and follow the code *without* the goto,\n>> something like:\n>>\n>> scratch_buffer_init (...);\n>> while (1)\n>>    {\n>>      while ((status = internal_getent (...)) == NSS_STATUS_SUCCESS)\n>>        {\n>>          ...\n>>        }\n>>      if (status == NSS_STATUS_TRYAGAIN)\n>>        if (!scratch_buffer_grow (&tmp_buffer))\n>>          {\n>>            *herrnop = NETDB_INTERNAL;\n>>            status = NSS_STATUS_TRYAGAIN;\n>>            break;\n>>          }\n>>      else\n>>        status = NSS_STATUS_SUCCESS;\n>>    }\n>> scratch_buffer_free (...);\n> \n> Right, I think I'll make this change in the first (refactoring) patch.\n\nI made this change in this patch instead.  Still okay?\n\nThanks,\nFlorian\n2017-10-10  Florian Weimer  <fweimer@redhat.com>\n\n\t[BZ #18023]\n\t* nss/nss_files/files-hosts.c (gethostbyname3_multi): Use struct\n\tscratch_buffer.  Eliminate gotos.\n\ndiff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c\nindex 867c10c2ef..763fa39a47 100644\n--- a/nss/nss_files/files-hosts.c\n+++ b/nss/nss_files/files-hosts.c\n@@ -22,6 +22,7 @@\n #include <arpa/nameser.h>\n #include <netdb.h>\n #include <resolv/resolv-internal.h>\n+#include <scratch_buffer.h>\n \n \n /* Get implementation for some internal functions.  */\n@@ -121,15 +122,12 @@ gethostbyname3_multi (FILE * stream, const char *name, int af,\n \t\t      int *errnop, int *herrnop, int flags)\n {\n   /* We have to get all host entries from the file.  */\n-  size_t tmp_buflen = MIN (buflen, 4096);\n-  char tmp_buffer_stack[tmp_buflen]\n-    __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));\n-  char *tmp_buffer = tmp_buffer_stack;\n+  struct scratch_buffer tmp_buffer;\n+  scratch_buffer_init (&tmp_buffer);\n   struct hostent tmp_result_buf;\n   int naddrs = 1;\n   int naliases = 0;\n   char *bufferend;\n-  bool tmp_buffer_malloced = false;\n   enum nss_status status;\n \n   while (result->h_aliases[naliases] != NULL)\n@@ -137,181 +135,165 @@ gethostbyname3_multi (FILE * stream, const char *name, int af,\n \n   bufferend = (char *) &result->h_aliases[naliases + 1];\n \n- again:\n-  while ((status = internal_getent (stream, &tmp_result_buf, tmp_buffer,\n-\t\t\t\t    tmp_buflen, errnop, herrnop, af,\n-\t\t\t\t    flags))\n-\t == NSS_STATUS_SUCCESS)\n+  while (true)\n     {\n-      int matches = 1;\n-      struct hostent *old_result = result;\n-      result = &tmp_result_buf;\n-      /* The following piece is a bit clumsy but we want to use the\n-\t `LOOKUP_NAME_CASE' value.  The optimizer should do its\n-\t job.  */\n-      do\n+      status = internal_getent (stream, &tmp_result_buf, tmp_buffer.data,\n+\t\t\t\ttmp_buffer.length, errnop, herrnop, af,\n+\t\t\t\tflags);\n+      /* Enlarge the buffer if necessary.  */\n+      if (status == NSS_STATUS_TRYAGAIN && *herrnop == NETDB_INTERNAL\n+\t  && *errnop == ERANGE)\n \t{\n-\t  LOOKUP_NAME_CASE (h_name, h_aliases)\n-\t    result = old_result;\n-\t}\n-      while ((matches = 0));\n-\n-      if (matches)\n-\t{\n-\t  /* We could be very clever and try to recycle a few bytes\n-\t     in the buffer instead of generating new arrays.  But\n-\t     we are not doing this here since it's more work than\n-\t     it's worth.  Simply let the user provide a bit bigger\n-\t     buffer.  */\n-\t  char **new_h_addr_list;\n-\t  char **new_h_aliases;\n-\t  int newaliases = 0;\n-\t  size_t newstrlen = 0;\n-\t  int cnt;\n-\n-\t  /* Count the new aliases and the length of the strings.  */\n-\t  while (tmp_result_buf.h_aliases[newaliases] != NULL)\n-\t    {\n-\t      char *cp = tmp_result_buf.h_aliases[newaliases];\n-\t      ++newaliases;\n-\t      newstrlen += strlen (cp) + 1;\n-\t    }\n-\t  /* If the real name is different add it also to the\n-\t     aliases.  This means that there is a duplication\n-\t     in the alias list but this is really the user's\n-\t     problem.  */\n-\t  if (strcmp (old_result->h_name,\n-\t\t      tmp_result_buf.h_name) != 0)\n-\t    {\n-\t      ++newaliases;\n-\t      newstrlen += strlen (tmp_result_buf.h_name) + 1;\n-\t    }\n-\n-\t  /* Make sure bufferend is aligned.  */\n-\t  assert ((bufferend - (char *) 0) % sizeof (char *) == 0);\n-\n-\t  /* Now we can check whether the buffer is large enough.\n-\t     16 is the maximal size of the IP address.  */\n-\t  if (bufferend + 16 + (naddrs + 2) * sizeof (char *)\n-\t      + roundup (newstrlen, sizeof (char *))\n-\t      + (naliases + newaliases + 1) * sizeof (char *)\n-\t      >= buffer + buflen)\n-\t    {\n-\t      *errnop = ERANGE;\n-\t      *herrnop = NETDB_INTERNAL;\n-\t      status = NSS_STATUS_TRYAGAIN;\n-\t      goto out;\n-\t    }\n-\n-\t  new_h_addr_list =\n-\t    (char **) (bufferend\n-\t\t       + roundup (newstrlen, sizeof (char *))\n-\t\t       + 16);\n-\t  new_h_aliases =\n-\t    (char **) ((char *) new_h_addr_list\n-\t\t       + (naddrs + 2) * sizeof (char *));\n-\n-\t  /* Copy the old data in the new arrays.  */\n-\t  for (cnt = 0; cnt < naddrs; ++cnt)\n-\t    new_h_addr_list[cnt] = old_result->h_addr_list[cnt];\n-\n-\t  for (cnt = 0; cnt < naliases; ++cnt)\n-\t    new_h_aliases[cnt] = old_result->h_aliases[cnt];\n-\n-\t  /* Store the new strings.  */\n-\t  cnt = 0;\n-\t  while (tmp_result_buf.h_aliases[cnt] != NULL)\n-\t    {\n-\t      new_h_aliases[naliases++] = bufferend;\n-\t      bufferend = (__stpcpy (bufferend,\n-\t\t\t\t     tmp_result_buf.h_aliases[cnt])\n-\t\t\t   + 1);\n-\t      ++cnt;\n-\t    }\n-\n-\t  if (cnt < newaliases)\n+\t  if (!scratch_buffer_grow (&tmp_buffer))\n \t    {\n-\t      new_h_aliases[naliases++] = bufferend;\n-\t      bufferend = __stpcpy (bufferend,\n-\t\t\t\t    tmp_result_buf.h_name) + 1;\n+\t      *errnop = ENOMEM;\n+\t      /* *herrnop and status already have the right value.  */\n+\t      break;\n \t    }\n-\n-\t  /* Final NULL pointer.  */\n-\t  new_h_aliases[naliases] = NULL;\n-\n-\t  /* Round up the buffer end address.  */\n-\t  bufferend += (sizeof (char *)\n-\t\t\t- ((bufferend - (char *) 0)\n-\t\t\t   % sizeof (char *))) % sizeof (char *);\n-\n-\t  /* Now the new address.  */\n-\t  new_h_addr_list[naddrs++] =\n-\t    memcpy (bufferend, tmp_result_buf.h_addr,\n-\t\t    tmp_result_buf.h_length);\n-\n-\t  /* Also here a final NULL pointer.  */\n-\t  new_h_addr_list[naddrs] = NULL;\n-\n-\t  /* Store the new array pointers.  */\n-\t  old_result->h_aliases = new_h_aliases;\n-\t  old_result->h_addr_list = new_h_addr_list;\n-\n-\t  /* Compute the new buffer end.  */\n-\t  bufferend = (char *) &new_h_aliases[naliases + 1];\n-\t  assert (bufferend <= buffer + buflen);\n-\n-\t  result = old_result;\n+\t  /* Loop around and retry with a larger buffer.  */\n \t}\n-    }\n-\n-  if (status == NSS_STATUS_TRYAGAIN)\n-    {\n-      size_t newsize = 2 * tmp_buflen;\n-      if (tmp_buffer_malloced)\n+      else if (status == NSS_STATUS_SUCCESS)\n \t{\n-\t  char *newp = realloc (tmp_buffer, newsize);\n-\t  if (newp != NULL)\n+\t  /* A line was read.  Check that it matches the search\n+\t     criteria.  */\n+\n+\t  int matches = 1;\n+\t  struct hostent *old_result = result;\n+\t  result = &tmp_result_buf;\n+\t  /* The following piece is a bit clumsy but we want to use\n+\t     the `LOOKUP_NAME_CASE' value.  The optimizer should do\n+\t     its job.  */\n+\t  do\n \t    {\n-\t      assert ((((uintptr_t) newp)\n-\t\t       & (__alignof__ (struct hostent_data) - 1))\n-\t\t      == 0);\n-\t      tmp_buffer = newp;\n-\t      tmp_buflen = newsize;\n-\t      goto again;\n+\t      LOOKUP_NAME_CASE (h_name, h_aliases)\n+\t\tresult = old_result;\n \t    }\n-\t}\n-      else if (!__libc_use_alloca (buflen + newsize))\n-\t{\n-\t  tmp_buffer = malloc (newsize);\n-\t  if (tmp_buffer != NULL)\n+\t  while ((matches = 0));\n+\n+\t  if (matches)\n \t    {\n-\t      assert ((((uintptr_t) tmp_buffer)\n-\t\t       & (__alignof__ (struct hostent_data) - 1))\n-\t\t      == 0);\n-\t      tmp_buffer_malloced = true;\n-\t      tmp_buflen = newsize;\n-\t      goto again;\n-\t    }\n-\t}\n+\t      /* We could be very clever and try to recycle a few bytes\n+\t\t in the buffer instead of generating new arrays.  But\n+\t\t we are not doing this here since it's more work than\n+\t\t it's worth.  Simply let the user provide a bit bigger\n+\t\t buffer.  */\n+\t      char **new_h_addr_list;\n+\t      char **new_h_aliases;\n+\t      int newaliases = 0;\n+\t      size_t newstrlen = 0;\n+\t      int cnt;\n+\n+\t      /* Count the new aliases and the length of the strings.  */\n+\t      while (tmp_result_buf.h_aliases[newaliases] != NULL)\n+\t\t{\n+\t\t  char *cp = tmp_result_buf.h_aliases[newaliases];\n+\t\t  ++newaliases;\n+\t\t  newstrlen += strlen (cp) + 1;\n+\t\t}\n+\t      /* If the real name is different add it also to the\n+\t\t aliases.  This means that there is a duplication\n+\t\t in the alias list but this is really the user's\n+\t\t problem.  */\n+\t      if (strcmp (old_result->h_name,\n+\t\t\t  tmp_result_buf.h_name) != 0)\n+\t\t{\n+\t\t  ++newaliases;\n+\t\t  newstrlen += strlen (tmp_result_buf.h_name) + 1;\n+\t\t}\n+\n+\t      /* Make sure bufferend is aligned.  */\n+\t      assert ((bufferend - (char *) 0) % sizeof (char *) == 0);\n+\n+\t      /* Now we can check whether the buffer is large enough.\n+\t\t 16 is the maximal size of the IP address.  */\n+\t      if (bufferend + 16 + (naddrs + 2) * sizeof (char *)\n+\t\t  + roundup (newstrlen, sizeof (char *))\n+\t\t  + (naliases + newaliases + 1) * sizeof (char *)\n+\t\t  >= buffer + buflen)\n+\t\t{\n+\t\t  *errnop = ERANGE;\n+\t\t  *herrnop = NETDB_INTERNAL;\n+\t\t  status = NSS_STATUS_TRYAGAIN;\n+\t\t  break;\n+\t\t}\n+\n+\t      new_h_addr_list =\n+\t\t(char **) (bufferend\n+\t\t\t   + roundup (newstrlen, sizeof (char *))\n+\t\t\t   + 16);\n+\t      new_h_aliases =\n+\t\t(char **) ((char *) new_h_addr_list\n+\t\t\t   + (naddrs + 2) * sizeof (char *));\n+\n+\t      /* Copy the old data in the new arrays.  */\n+\t      for (cnt = 0; cnt < naddrs; ++cnt)\n+\t\tnew_h_addr_list[cnt] = old_result->h_addr_list[cnt];\n+\n+\t      for (cnt = 0; cnt < naliases; ++cnt)\n+\t\tnew_h_aliases[cnt] = old_result->h_aliases[cnt];\n+\n+\t      /* Store the new strings.  */\n+\t      cnt = 0;\n+\t      while (tmp_result_buf.h_aliases[cnt] != NULL)\n+\t\t{\n+\t\t  new_h_aliases[naliases++] = bufferend;\n+\t\t  bufferend = (__stpcpy (bufferend,\n+\t\t\t\t\t tmp_result_buf.h_aliases[cnt])\n+\t\t\t       + 1);\n+\t\t  ++cnt;\n+\t\t}\n+\n+\t      if (cnt < newaliases)\n+\t\t{\n+\t\t  new_h_aliases[naliases++] = bufferend;\n+\t\t  bufferend = __stpcpy (bufferend,\n+\t\t\t\t\ttmp_result_buf.h_name) + 1;\n+\t\t}\n+\n+\t      /* Final NULL pointer.  */\n+\t      new_h_aliases[naliases] = NULL;\n+\n+\t      /* Round up the buffer end address.  */\n+\t      bufferend += (sizeof (char *)\n+\t\t\t    - ((bufferend - (char *) 0)\n+\t\t\t       % sizeof (char *))) % sizeof (char *);\n+\n+\t      /* Now the new address.  */\n+\t      new_h_addr_list[naddrs++] =\n+\t\tmemcpy (bufferend, tmp_result_buf.h_addr,\n+\t\t\ttmp_result_buf.h_length);\n+\n+\t      /* Also here a final NULL pointer.  */\n+\t      new_h_addr_list[naddrs] = NULL;\n+\n+\t      /* Store the new array pointers.  */\n+\t      old_result->h_aliases = new_h_aliases;\n+\t      old_result->h_addr_list = new_h_addr_list;\n+\n+\t      /* Compute the new buffer end.  */\n+\t      bufferend = (char *) &new_h_aliases[naliases + 1];\n+\t      assert (bufferend <= buffer + buflen);\n+\n+\t      result = old_result;\n+\t    } /* If match was found.  */\n+\n+\t  /* If no match is found, loop around and fetch another\n+\t     line.  */\n+\n+\t} /* status == NSS_STATUS_SUCCESS.  */\n       else\n-\t{\n-\t  tmp_buffer\n-\t    = extend_alloca (tmp_buffer, tmp_buflen,\n-\t\t\t     newsize\n-\t\t\t     + __alignof__ (struct hostent_data));\n-\t  tmp_buffer = (char *) (((uintptr_t) tmp_buffer\n-\t\t\t\t  + __alignof__ (struct hostent_data)\n-\t\t\t\t  - 1)\n-\t\t\t\t & ~(__alignof__ (struct hostent_data)\n-\t\t\t\t     - 1));\n-\t  goto again;\n-\t}\n-    }\n-  else\n+\t/* internal_getent returned an error.  */\n+\tbreak;\n+    } /* while (true) */\n+\n+  /* Propagate the NSS_STATUS_TRYAGAIN error to the caller.  It means\n+     that we may not have loaded the complete result.\n+     NSS_STATUS_NOTFOUND, however, means that we reached the end of\n+     the file successfully.  */\n+  if (status != NSS_STATUS_TRYAGAIN)\n     status = NSS_STATUS_SUCCESS;\n- out:\n-  if (tmp_buffer_malloced)\n-    free (tmp_buffer);\n+\n+  scratch_buffer_free (&tmp_buffer);\n   return status;\n }","headers":{"Return-Path":"<libc-alpha-return-85576-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-85576-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"EtAA04m0\"; dkim-atps=neutral","sourceware.org; auth=none","ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx07.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=fweimer@redhat.com"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yBHMJ2k1Tz9tYM\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 11 Oct 2017 00:02:20 +1100 (AEDT)","(qmail 68704 invoked by alias); 10 Oct 2017 13:02:08 -0000","(qmail 67292 invoked by uid 89); 10 Oct 2017 13:02:05 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:from:to:references:message-id:date\n\t:mime-version:in-reply-to:content-type; q=dns; s=default; b=IDah\n\tUFPSOHUnKU54tLPSdBeAxBfjxKdUwheW9TXup/osCAUCyw+aOyz+dOr6S9u8kXWI\n\t60n0cCUodKuGVsM8vHUl1lsGoKDcqQ0Eylb7cqP6p3WYgcNui6cJx9pHFQAfLdpz\n\thuIOFXi+W0nm9TE8Rrf3mbZbaPBx9pSeuhm221g=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:from:to:references:message-id:date\n\t:mime-version:in-reply-to:content-type; s=default; bh=JCbz84Kl5x\n\tsSZsJQlZ7TnbFrpGE=; b=EtAA04m0UTcAeWnYXqeGHd9itthougyvMfE4dJOArN\n\t17osJuih60tmitR9dVFJeFXCvpdFRi5fxC/JwawK4COMK1a3ejjyxQvKcaTRDzwl\n\tcRtoO3zG9dCKMtC+fnpRgdgGoTjWFO0m3dYSbl/NHiyknQPXdpVNIOl2I1RrjsVB\n\to=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD,\n\tSPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Round,\n\tenlarge","X-HELO":"mx1.redhat.com","DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com A3564C04AC74","Subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","From":"Florian Weimer <fweimer@redhat.com>","To":"Adhemerval Zanella <adhemerval.zanella@linaro.org>,\n\tlibc-alpha@sourceware.org","References":"<20170904173123.9C550439942E3@oldenburg.str.redhat.com>\n\t<426c9fe6-2b88-96c0-2382-651cf30f2db8@linaro.org>\n\t<81d77843-06c8-ec51-23b1-542a90d5af4e@redhat.com>","Message-ID":"<864301dd-4e83-30ec-d690-b2dbaa3864dc@redhat.com>","Date":"Tue, 10 Oct 2017 15:01:58 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<81d77843-06c8-ec51-23b1-542a90d5af4e@redhat.com>","Content-Type":"multipart/mixed;\n\tboundary=\"------------33EDD14BC731D74E51828973\""}},{"id":1784291,"web_url":"http://patchwork.ozlabs.org/comment/1784291/","msgid":"<544e1d74-4c6f-821c-2094-53df5f7179db@redhat.com>","list_archive_url":null,"date":"2017-10-11T05:04:50","subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","submitter":{"id":14312,"url":"http://patchwork.ozlabs.org/api/people/14312/","name":"Florian Weimer","email":"fweimer@redhat.com"},"content":"On 10/10/2017 03:01 PM, Florian Weimer wrote:\n> On 09/05/2017 08:38 PM, Florian Weimer wrote:\n> \n>>> I do think this it is easier to read and follow the code *without* \n>>> the goto,\n>>> something like:\n>>>\n>>> scratch_buffer_init (...);\n>>> while (1)\n>>>    {\n>>>      while ((status = internal_getent (...)) == NSS_STATUS_SUCCESS)\n>>>        {\n>>>          ...\n>>>        }\n>>>      if (status == NSS_STATUS_TRYAGAIN)\n>>>        if (!scratch_buffer_grow (&tmp_buffer))\n>>>          {\n>>>            *herrnop = NETDB_INTERNAL;\n>>>            status = NSS_STATUS_TRYAGAIN;\n>>>            break;\n>>>          }\n>>>      else\n>>>        status = NSS_STATUS_SUCCESS;\n>>>    }\n>>> scratch_buffer_free (...);\n>>\n>> Right, I think I'll make this change in the first (refactoring) patch.\n> \n> I made this change in this patch instead.  Still okay?\n\nI'm going to push this because you've already acked the subsequent patch.\n\nThanks,\nFlorian","headers":{"Return-Path":"<libc-alpha-return-85624-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-85624-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"tOEIyxW2\"; dkim-atps=neutral","sourceware.org; auth=none","ext-mx01.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx01.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=fweimer@redhat.com"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yBhk655Xhz9sRW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 11 Oct 2017 16:05:02 +1100 (AEDT)","(qmail 8389 invoked by alias); 11 Oct 2017 05:04:55 -0000","(qmail 8377 invoked by uid 89); 11 Oct 2017 05:04:54 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:from:to:references:message-id:date\n\t:mime-version:in-reply-to:content-type\n\t:content-transfer-encoding; q=dns; s=default; b=SW8ditkBeU8MOErq\n\tAXq4Hrcis7mhtr/BhvtPk6vd5P4lyb4uWJn29ikKhpfu+M0FTbIy5G87RQ5Qcuoe\n\tT9UyhZKV/aF2yN+dus7nNRlw4MYRw0bu0G6gOe/JYiCMptJ6nfK3vLwfq5hlXxQt\n\tp2No9u7vwYvX5Tq8sser9vzRpNk=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:from:to:references:message-id:date\n\t:mime-version:in-reply-to:content-type\n\t:content-transfer-encoding; s=default; bh=tV9kTKZgs/jQw3CEgC5NyS\n\tG91NE=; b=tOEIyxW2GF7E/eX3ZnlbFxtH6N8YZZcHvThrMsh7BXjOibboU6EcXh\n\txoKe/AOY8TTHDz4Fqb9rrP10flEmGCBbu1b4lR4HcbZNF8UCyaLbB4tIh9MTQWs5\n\tMOx9CiDgS8AYBX7i3mAqpahXXPy19IHHX4lRWl8ygvwc8c1K0FR3I=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-0.9 required=5.0 tests=BAYES_00,\n\tKAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD,\n\tSPF_HELO_PASS autolearn=no version=3.3.2\n\tspammy=Hx-languages-length:1089,\n\tHContent-Transfer-Encoding:8bit","X-HELO":"mx1.redhat.com","DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 4578081DE2","Subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","From":"Florian Weimer <fweimer@redhat.com>","To":"Adhemerval Zanella <adhemerval.zanella@linaro.org>,\n\tlibc-alpha@sourceware.org","References":"<20170904173123.9C550439942E3@oldenburg.str.redhat.com>\n\t<426c9fe6-2b88-96c0-2382-651cf30f2db8@linaro.org>\n\t<81d77843-06c8-ec51-23b1-542a90d5af4e@redhat.com>\n\t<864301dd-4e83-30ec-d690-b2dbaa3864dc@redhat.com>","Message-ID":"<544e1d74-4c6f-821c-2094-53df5f7179db@redhat.com>","Date":"Wed, 11 Oct 2017 07:04:50 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<864301dd-4e83-30ec-d690-b2dbaa3864dc@redhat.com>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"8bit"}},{"id":1784562,"web_url":"http://patchwork.ozlabs.org/comment/1784562/","msgid":"<9f427a18-421b-2176-da19-b7a33dcd72d5@linaro.org>","list_archive_url":null,"date":"2017-10-11T12:18:39","subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","submitter":{"id":66065,"url":"http://patchwork.ozlabs.org/api/people/66065/","name":"Adhemerval Zanella Netto","email":"adhemerval.zanella@linaro.org"},"content":"On 11/10/2017 02:04, Florian Weimer wrote:\n> On 10/10/2017 03:01 PM, Florian Weimer wrote:\n>> On 09/05/2017 08:38 PM, Florian Weimer wrote:\n>>\n>>>> I do think this it is easier to read and follow the code *without* the goto,\n>>>> something like:\n>>>>\n>>>> scratch_buffer_init (...);\n>>>> while (1)\n>>>>    {\n>>>>      while ((status = internal_getent (...)) == NSS_STATUS_SUCCESS)\n>>>>        {\n>>>>          ...\n>>>>        }\n>>>>      if (status == NSS_STATUS_TRYAGAIN)\n>>>>        if (!scratch_buffer_grow (&tmp_buffer))\n>>>>          {\n>>>>            *herrnop = NETDB_INTERNAL;\n>>>>            status = NSS_STATUS_TRYAGAIN;\n>>>>            break;\n>>>>          }\n>>>>      else\n>>>>        status = NSS_STATUS_SUCCESS;\n>>>>    }\n>>>> scratch_buffer_free (...);\n>>>\n>>> Right, I think I'll make this change in the first (refactoring) patch.\n>>\n>> I made this change in this patch instead.  Still okay?\n> \n> I'm going to push this because you've already acked the subsequent patch.\n\nLGTM, I though I had acked this patch as well (I did spend some time yesterday\nchecking the new version).","headers":{"Return-Path":"<libc-alpha-return-85636-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-85636-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"IewaXOJ/\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yBtLt1g6Tz9s7p\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 11 Oct 2017 23:19:01 +1100 (AEDT)","(qmail 82544 invoked by alias); 11 Oct 2017 12:18:55 -0000","(qmail 77822 invoked by uid 89); 11 Oct 2017 12:18:52 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:to:references:from:message-id:date\n\t:mime-version:in-reply-to:content-type\n\t:content-transfer-encoding; q=dns; s=default; b=qGztYm0FinEmNQbN\n\tL+znbN9RkOlI4Vyeo4CmO33iwmkuROHQlrlZx7HyhnYcHl7JvFEm6kBKSWlp0i9o\n\tyYCwLAtebCl/hfyjzSs1jFuOucxE/Wi1bhM22lLHOdr1LGt9G5HoFT6veLUpo+vD\n\tScVbM8uLiqzpxtvumUhCD94Hx+s=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:subject:to:references:from:message-id:date\n\t:mime-version:in-reply-to:content-type\n\t:content-transfer-encoding; s=default; bh=7bGRviv6rv+xjP+Fhrp95X\n\te774Y=; b=IewaXOJ/eC1UGzh1lYbkG2BmCe8uTNKAr45JHcXX2DyjFlkW/pfDjJ\n\tWSNFybbVUHm0CJeOuhhOAJsQ4QlQWXi38Z89pk9uB/b4cHw2OgVR/ytzIKeHvUbn\n\tfJYQD3f9gNkJUukffW9kujB/f2XrIfmpRNIvTuuSZr0bTsKv4Kj1w=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-2.1 required=5.0 tests=BAYES_00,\n\tRCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=spend,\n\tHContent-Transfer-Encoding:8bit","X-HELO":"mail-qt0-f182.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=Kr9hxqpJUiUgvsmjKla6HL8jl1DE+5GOGP8/jREA4/4=;\n\tb=nUUKVlun3mpap2PBk6FzH5JuhluzdDWUK7JavVD7Js0L4Pa/1YBYAJMoL1k+uEuzuU\n\tClntjt6yD952OHuQRt7HLnuYA3lGQvL0Lfvz4NYltSPVLeudZDU52071TfNlJtSLourT\n\tko/GqfM1GeN0L+y5STMsoZq5L7LjFYdeOV/U8J16cThkHC52DvnXLidhu/D1i1Mz0rpU\n\tEsf+fG3RIwFuWMRzhieYoQPZqt8myq+6UOTMGqSFykqUNTPC8bGAJqd0avEujg4yrRvX\n\thtu4VvOjjb6XJjYSh4NFG3nv6qsXb8BgZ/kktQO44pK8yulCxfeHHARk2CB+iie24a8t\n\t5cWA==","X-Gm-Message-State":"AMCzsaXg+acu5pS8QgMlXp7UKeLSCNFupRxYMZZ8CxEY7PYgfpA/yYUs\n\taEsPvrxjwk9S+L0P/NTTcIah1jLeJp4=","X-Google-Smtp-Source":"AOwi7QAq0tepMoFuJtMS4IQKqLFktITcKvhAS4YXavZpjPbazDCP9iF0KrcUMISkJuGDZMt4vnXYdA==","X-Received":"by 10.55.80.7 with SMTP id e7mr18787789qkb.213.1507724324208;\n\tWed, 11 Oct 2017 05:18:44 -0700 (PDT)","Subject":"Re: [PATCH] nss_files: Use struct scratch_buffer for gethostbyname\n\t[BZ #18023]","To":"Florian Weimer <fweimer@redhat.com>, libc-alpha@sourceware.org","References":"<20170904173123.9C550439942E3@oldenburg.str.redhat.com>\n\t<426c9fe6-2b88-96c0-2382-651cf30f2db8@linaro.org>\n\t<81d77843-06c8-ec51-23b1-542a90d5af4e@redhat.com>\n\t<864301dd-4e83-30ec-d690-b2dbaa3864dc@redhat.com>\n\t<544e1d74-4c6f-821c-2094-53df5f7179db@redhat.com>","From":"Adhemerval Zanella <adhemerval.zanella@linaro.org>","Message-ID":"<9f427a18-421b-2176-da19-b7a33dcd72d5@linaro.org>","Date":"Wed, 11 Oct 2017 09:18:39 -0300","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<544e1d74-4c6f-821c-2094-53df5f7179db@redhat.com>","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"8bit"}}]