From 352f4ff9a268b81ef5d4b2413f582565806e4790 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 30 Jun 2017 21:10:23 +0200 Subject: resolv: Introduce struct resolv_context [BZ #21668] struct resolv_context objects provide a temporary resolver context which does not change during a name lookup operation. Only when the outmost context is created, the stub resolver configuration is verified to be current (at present, only against previous res_init calls). Subsequent attempts to obtain the context will reuse the result of the initial verification operation. struct resolv_context can also be extended in the future to store data which needs to be deallocated during thread cancellation. --- nss/getXXbyYY.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'nss/getXXbyYY.c') diff --git a/nss/getXXbyYY.c b/nss/getXXbyYY.c index d027b14250..a439b816f7 100644 --- a/nss/getXXbyYY.c +++ b/nss/getXXbyYY.c @@ -47,6 +47,11 @@ |* *| \*******************************************************************/ + +#ifdef HANDLE_DIGITS_DOTS +# include +#endif + /* To make the real sources a bit prettier. */ #define REENTRANT_NAME APPEND_R (FUNCTION_NAME) #define APPEND_R(name) APPEND_R1 (name) @@ -93,6 +98,19 @@ FUNCTION_NAME (ADD_PARAMS) int h_errno_tmp = 0; #endif +#ifdef HANDLE_DIGITS_DOTS + /* Wrap both __nss_hostname_digits_dots and the actual lookup + function call in the same context. */ + struct resolv_context *res_ctx = __resolv_context_get (); + if (res_ctx == NULL) + { +# if NEED_H_ERRNO + __set_h_errno (NETDB_INTERNAL); +# endif + return NULL; + } +#endif + /* Get lock. */ __libc_lock_lock (lock); @@ -105,9 +123,9 @@ FUNCTION_NAME (ADD_PARAMS) #ifdef HANDLE_DIGITS_DOTS if (buffer != NULL) { - if (__nss_hostname_digits_dots (name, &resbuf, &buffer, - &buffer_size, 0, &result, NULL, AF_VAL, - H_ERRNO_VAR_P)) + if (__nss_hostname_digits_dots_context + (res_ctx, name, &resbuf, &buffer, &buffer_size, 0, &result, NULL, + AF_VAL, H_ERRNO_VAR_P)) goto done; } #endif @@ -143,6 +161,10 @@ done: /* Release lock. */ __libc_lock_unlock (lock); +#ifdef HANDLE_DIGITS_DOTS + __resolv_context_put (res_ctx); +#endif + #ifdef NEED_H_ERRNO if (h_errno_tmp != 0) __set_h_errno (h_errno_tmp); -- cgit 1.4.1