Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/809772/?format=api
{ "id": 809772, "url": "http://patchwork.ozlabs.org/api/patches/809772/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/patch/20170904173046.DA957439942E3@oldenburg.str.redhat.com/", "project": { "id": 41, "url": "http://patchwork.ozlabs.org/api/projects/41/?format=api", "name": "GNU C Library", "link_name": "glibc", "list_id": "libc-alpha.sourceware.org", "list_email": "libc-alpha@sourceware.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170904173046.DA957439942E3@oldenburg.str.redhat.com>", "list_archive_url": null, "date": "2017-09-04T17:30:46", "name": "nss_files: Refactor gethostbyname3 multi case into separate function", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "b0b317b568c6eece78401d21a85acc8edf8e0265", "submitter": { "id": 14312, "url": "http://patchwork.ozlabs.org/api/people/14312/?format=api", "name": "Florian Weimer", "email": "fweimer@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/glibc/patch/20170904173046.DA957439942E3@oldenburg.str.redhat.com/mbox/", "series": [ { "id": 1427, "url": "http://patchwork.ozlabs.org/api/series/1427/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/list/?series=1427", "date": "2017-09-04T17:30:46", "name": "nss_files: Refactor gethostbyname3 multi case into separate function", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/1427/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/809772/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/809772/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<libc-alpha-return-84172-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-84172-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=\"D2FPcQRf\"; dkim-atps=neutral", "sourceware.org; auth=none", "ext-mx02.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com", "ext-mx02.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 3xmH2F2s9Xz9s4s\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 5 Sep 2017 03:31:17 +1000 (AEST)", "(qmail 105547 invoked by alias); 4 Sep 2017 17:31:08 -0000", "(qmail 94644 invoked by uid 89); 4 Sep 2017 17:30:59 -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:date:to:subject:mime-version:content-type\n\t:content-transfer-encoding:message-id:from; q=dns; s=default; b=\n\tjwwetH0+VDEEynyF/5ohUN2YmxUfNDSWCmm2Xwjwv4Xc17xE/mA9syQMmpLXXTBW\n\tdBhzZLUAw+poejpypHGmfJ9+uBLeR+p8oJ7kpJBL7kXYtbZiIVrm381Rab+fbppB\n\tFE+PALppqf/Q2R2EPc8qdTwRFQSsSnVOBQDSfCSL6ck=", "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:date:to:subject:mime-version:content-type\n\t:content-transfer-encoding:message-id:from; s=default; bh=+/gpFx\n\t0QETmKoYWmoX5a1ZOY7Oo=; b=D2FPcQRfIVBQUAr/txcG9Aw2sf9/FqCQLi+RN6\n\tVYQ3WsWJXTQnZ2G3MkLy2sJEM0vyL9BwJR62tC5CNVl8K0nyPGUNfPf3k2r9MuLD\n\tQ0DYQbtrpdxbf+NPLET/WlSEPfrgWiG8z1wexGGFDTSo7n/ox+lROTuKRROxJtm8\n\twTDBs=", "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=Simply", "X-HELO": "mx1.redhat.com", "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com BD7859B0E4", "Date": "Mon, 04 Sep 2017 19:30:46 +0200", "To": "libc-alpha@sourceware.org", "Subject": "[PATCH] nss_files: Refactor gethostbyname3 multi case into\n\tseparate function", "User-Agent": "Heirloom mailx 12.5 7/5/10", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=us-ascii", "Content-Transfer-Encoding": "7bit", "Message-Id": "<20170904173046.DA957439942E3@oldenburg.str.redhat.com>", "From": "fweimer@redhat.com (Florian Weimer)" }, "content": "This is in preparation of further cleanup work.\n\n2017-09-04 Florian Weimer <fweimer@redhat.com>\n\n\t* nss/nss_files/files-hosts.c (gethostbyname3_multi): New\n\tfunction.\n\t(_nss_files_gethostbyname3_r): Call it.", "diff": "diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c\nindex bccb6a5780..867c10c2ef 100644\n--- a/nss/nss_files/files-hosts.c\n+++ b/nss/nss_files/files-hosts.c\n@@ -115,6 +115,206 @@ DB_LOOKUP (hostbyaddr, ,,,\n \t }, const void *addr, socklen_t len, int af)\n #undef EXTRA_ARGS_VALUE\n \n+static enum nss_status\n+gethostbyname3_multi (FILE * stream, const char *name, int af,\n+\t\t struct hostent *result, char *buffer, size_t buflen,\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 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+ ++naliases;\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+ {\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+\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 {\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 }\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}\n+ }\n+\n+ if (status == NSS_STATUS_TRYAGAIN)\n+ {\n+ size_t newsize = 2 * tmp_buflen;\n+ if (tmp_buffer_malloced)\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}\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+ status = NSS_STATUS_SUCCESS;\n+ out:\n+ if (tmp_buffer_malloced)\n+ free (tmp_buffer);\n+ return status;\n+}\n+\n enum nss_status\n _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,\n \t\t\t char *buffer, size_t buflen, int *errnop,\n@@ -143,199 +343,8 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,\n \n if (status == NSS_STATUS_SUCCESS\n \t && _res_hconf.flags & HCONF_FLAG_MULTI)\n-\t{\n-\t /* We have to get all host entries from the file. */\n-\t size_t tmp_buflen = MIN (buflen, 4096);\n-\t char tmp_buffer_stack[tmp_buflen]\n-\t __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));\n-\t char *tmp_buffer = tmp_buffer_stack;\n-\t struct hostent tmp_result_buf;\n-\t int naddrs = 1;\n-\t int naliases = 0;\n-\t char *bufferend;\n-\t bool tmp_buffer_malloced = false;\n-\n-\t while (result->h_aliases[naliases] != NULL)\n-\t ++naliases;\n-\n-\t bufferend = (char *) &result->h_aliases[naliases + 1];\n-\n-\tagain:\n-\t while ((status = internal_getent (stream, &tmp_result_buf, tmp_buffer,\n-\t\t\t\t\t tmp_buflen, errnop, herrnop, af,\n-\t\t\t\t\t flags))\n-\t\t == NSS_STATUS_SUCCESS)\n-\t {\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 the\n-\t\t `LOOKUP_NAME_CASE' value. The optimizer should do its\n-\t\t job. */\n-\t do\n-\t\t{\n-\t\t LOOKUP_NAME_CASE (h_name, h_aliases)\n-\t\t result = old_result;\n-\t\t}\n-\t while ((matches = 0));\n-\n-\t if (matches)\n-\t\t{\n-\t\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\t char **new_h_addr_list;\n-\t\t char **new_h_aliases;\n-\t\t int newaliases = 0;\n-\t\t size_t newstrlen = 0;\n-\t\t int cnt;\n-\n-\t\t /* Count the new aliases and the length of the strings. */\n-\t\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\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\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\t /* Make sure bufferend is aligned. */\n-\t\t assert ((bufferend - (char *) 0) % sizeof (char *) == 0);\n-\n-\t\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\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 goto out;\n-\t\t }\n-\n-\t\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\t new_h_aliases =\n-\t\t (char **) ((char *) new_h_addr_list\n-\t\t\t + (naddrs + 2) * sizeof (char *));\n-\n-\t\t /* Copy the old data in the new arrays. */\n-\t\t for (cnt = 0; cnt < naddrs; ++cnt)\n-\t\t new_h_addr_list[cnt] = old_result->h_addr_list[cnt];\n-\n-\t\t for (cnt = 0; cnt < naliases; ++cnt)\n-\t\t new_h_aliases[cnt] = old_result->h_aliases[cnt];\n-\n-\t\t /* Store the new strings. */\n-\t\t cnt = 0;\n-\t\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\t + 1);\n-\t\t ++cnt;\n-\t\t }\n-\n-\t\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\t tmp_result_buf.h_name) + 1;\n-\t\t }\n-\n-\t\t /* Final NULL pointer. */\n-\t\t new_h_aliases[naliases] = NULL;\n-\n-\t\t /* Round up the buffer end address. */\n-\t\t bufferend += (sizeof (char *)\n-\t\t\t\t- ((bufferend - (char *) 0)\n-\t\t\t\t % sizeof (char *))) % sizeof (char *);\n-\n-\t\t /* Now the new address. */\n-\t\t new_h_addr_list[naddrs++] =\n-\t\t memcpy (bufferend, tmp_result_buf.h_addr,\n-\t\t\t tmp_result_buf.h_length);\n-\n-\t\t /* Also here a final NULL pointer. */\n-\t\t new_h_addr_list[naddrs] = NULL;\n-\n-\t\t /* Store the new array pointers. */\n-\t\t old_result->h_aliases = new_h_aliases;\n-\t\t old_result->h_addr_list = new_h_addr_list;\n-\n-\t\t /* Compute the new buffer end. */\n-\t\t bufferend = (char *) &new_h_aliases[naliases + 1];\n-\t\t assert (bufferend <= buffer + buflen);\n-\n-\t\t result = old_result;\n-\t\t}\n-\t }\n-\n-\t if (status == NSS_STATUS_TRYAGAIN)\n-\t {\n-\t size_t newsize = 2 * tmp_buflen;\n-\t if (tmp_buffer_malloced)\n-\t\t{\n-\t\t char *newp = realloc (tmp_buffer, newsize);\n-\t\t if (newp != NULL)\n-\t\t {\n-\t\t assert ((((uintptr_t) newp)\n-\t\t\t & (__alignof__ (struct hostent_data) - 1))\n-\t\t\t == 0);\n-\t\t tmp_buffer = newp;\n-\t\t tmp_buflen = newsize;\n-\t\t goto again;\n-\t\t }\n-\t\t}\n-\t else if (!__libc_use_alloca (buflen + newsize))\n-\t\t{\n-\t\t tmp_buffer = malloc (newsize);\n-\t\t if (tmp_buffer != NULL)\n-\t\t {\n-\t\t assert ((((uintptr_t) tmp_buffer)\n-\t\t\t & (__alignof__ (struct hostent_data) - 1))\n-\t\t\t == 0);\n-\t\t tmp_buffer_malloced = true;\n-\t\t tmp_buflen = newsize;\n-\t\t goto again;\n-\t\t }\n-\t\t}\n-\t else\n-\t\t{\n-\t\t tmp_buffer\n-\t\t = extend_alloca (tmp_buffer, tmp_buflen,\n-\t\t\t\t newsize\n-\t\t\t\t + __alignof__ (struct hostent_data));\n-\t\t tmp_buffer = (char *) (((uintptr_t) tmp_buffer\n-\t\t\t\t\t + __alignof__ (struct hostent_data)\n-\t\t\t\t\t - 1)\n-\t\t\t\t\t & ~(__alignof__ (struct hostent_data)\n-\t\t\t\t\t - 1));\n-\t\t goto again;\n-\t\t}\n-\t }\n-\t else\n-\t status = NSS_STATUS_SUCCESS;\n-\tout:\n-\t if (tmp_buffer_malloced)\n-\t free (tmp_buffer);\n-\t}\n+\tstatus = gethostbyname3_multi\n+\t (stream, name, af, result, buffer, buflen, errnop, herrnop, flags);\n \n internal_endent (&stream);\n }\n", "prefixes": [] }