From patchwork Sat Dec 1 20:14:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 30513 Received: (qmail 113514 invoked by alias); 1 Dec 2018 20:14:31 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 113391 invoked by uid 89); 1 Dec 2018 20:14:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=simplifies, ans X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] resolv: Set h_errno during resolver context allocation failure Date: Sat, 01 Dec 2018 21:14:16 +0100 Message-ID: <871s71m2cn.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 This simplifies the libresolv/libc interface. In addition, this change fixes a minor bug where the res_h_errno member of the per-thread (_res) state was updated, not the member of the specified resolver state. 2018-12-01 Florian Weimer * resolv/res_query.c (context_query_common, context_search_common) (context_querydomain_common, context_hostalias_common): Do not set h_errno on failure. * resolv/res_send.c (context_send_common): Likewise. * resolv/resolv_context.c (context_alloc): Set h_errno on memory allocation failure. diff --git a/resolv/res_query.c b/resolv/res_query.c index ebbe5a6a4e..047a133772 100644 --- a/resolv/res_query.c +++ b/resolv/res_query.c @@ -285,10 +285,7 @@ context_query_common (struct resolv_context *ctx, unsigned char *answer, int anslen) { if (ctx == NULL) - { - RES_SET_H_ERRNO (&_res, NETDB_INTERNAL); - return -1; - } + return -1; int result = __res_context_query (ctx, name, class, type, answer, anslen, NULL, NULL, NULL, NULL, NULL); __resolv_context_put (ctx); @@ -524,10 +521,7 @@ context_search_common (struct resolv_context *ctx, unsigned char *answer, int anslen) { if (ctx == NULL) - { - RES_SET_H_ERRNO (&_res, NETDB_INTERNAL); - return -1; - } + return -1; int result = __res_context_search (ctx, name, class, type, answer, anslen, NULL, NULL, NULL, NULL, NULL); __resolv_context_put (ctx); @@ -603,10 +597,7 @@ context_querydomain_common (struct resolv_context *ctx, unsigned char *answer, int anslen) { if (ctx == NULL) - { - RES_SET_H_ERRNO (&_res, NETDB_INTERNAL); - return -1; - } + return -1; int result = __res_context_querydomain (ctx, name, domain, class, type, answer, anslen, NULL, NULL, NULL, NULL, NULL); @@ -681,10 +672,7 @@ context_hostalias_common (struct resolv_context *ctx, const char *name, char *dst, size_t siz) { if (ctx == NULL) - { - RES_SET_H_ERRNO (&_res, NETDB_INTERNAL); - return NULL; - } + return NULL; const char *result = __res_context_hostalias (ctx, name, dst, siz); __resolv_context_put (ctx); return result; diff --git a/resolv/res_send.c b/resolv/res_send.c index 47e9de1f5b..c966f0ea67 100644 --- a/resolv/res_send.c +++ b/resolv/res_send.c @@ -554,10 +554,7 @@ context_send_common (struct resolv_context *ctx, unsigned char *ans, int anssiz) { if (ctx == NULL) - { - RES_SET_H_ERRNO (&_res, NETDB_INTERNAL); - return -1; - } + return -1; int result = __res_context_send (ctx, buf, buflen, NULL, 0, ans, anssiz, NULL, NULL, NULL, NULL, NULL); __resolv_context_put (ctx); diff --git a/resolv/resolv_context.c b/resolv/resolv_context.c index 4bd79111f0..7db8272292 100644 --- a/resolv/resolv_context.c +++ b/resolv/resolv_context.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -126,13 +127,18 @@ maybe_init (struct resolv_context *ctx, bool preinit) } /* Allocate a new context object and initialize it. The object is put - on the current list. */ + on the current list. On memory allocation failure, h_errno is set + to NETDB_INTERNAL. */ static struct resolv_context * context_alloc (struct __res_state *resp) { struct resolv_context *ctx = malloc (sizeof (*ctx)); if (ctx == NULL) - return NULL; + { + resp->res_h_errno = NETDB_INTERNAL; + __set_h_errno (NETDB_INTERNAL); + return NULL; + } ctx->resp = resp; ctx->conf = __resolv_conf_get (resp); ctx->__refcount = 1;