|
| 1 | +From def1a172f3a5ac13c3cd5687d2a352262b02e358 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Zhichun Wan <zhichunwan@microsoft.com> |
| 3 | +Date: Fri, 26 Jul 2024 22:30:10 +0000 |
| 4 | +Subject: [PATCH] patches |
| 5 | + |
| 6 | +--- |
| 7 | + Utilities/cmcurl/lib/hostip.c | 19 +++++++++++++++---- |
| 8 | + 1 file changed, 15 insertions(+), 4 deletions(-) |
| 9 | + |
| 10 | +diff --git a/Utilities/cmcurl/lib/hostip.c b/Utilities/cmcurl/lib/hostip.c |
| 11 | +index e0e3cfc2..a763ad84 100644 |
| 12 | +--- a/Utilities/cmcurl/lib/hostip.c |
| 13 | ++++ b/Utilities/cmcurl/lib/hostip.c |
| 14 | +@@ -72,12 +72,19 @@ |
| 15 | + #include <SystemConfiguration/SCDynamicStoreCopySpecific.h> |
| 16 | + #endif |
| 17 | + |
| 18 | +-#if defined(CURLRES_SYNCH) && \ |
| 19 | +- defined(HAVE_ALARM) && defined(SIGALRM) && defined(HAVE_SIGSETJMP) |
| 20 | ++#if defined(CURLRES_SYNCH) && \ |
| 21 | ++ defined(HAVE_ALARM) && \ |
| 22 | ++ defined(SIGALRM) && \ |
| 23 | ++ defined(HAVE_SIGSETJMP) && \ |
| 24 | ++ defined(GLOBAL_INIT_IS_THREADSAFE) |
| 25 | + /* alarm-based timeouts can only be used with all the dependencies satisfied */ |
| 26 | + #define USE_ALARM_TIMEOUT |
| 27 | + #endif |
| 28 | + |
| 29 | ++#ifdef USE_ALARM_TIMEOUT |
| 30 | ++#include "easy_lock.h" |
| 31 | ++#endif |
| 32 | ++ |
| 33 | + #define MAX_HOSTCACHE_LEN (255 + 7) /* max FQDN + colon + port number + zero */ |
| 34 | + |
| 35 | + /* |
| 36 | +@@ -249,11 +256,12 @@ void Curl_hostcache_prune(struct Curl_easy *data) |
| 37 | + Curl_share_unlock(data, CURL_LOCK_DATA_DNS); |
| 38 | + } |
| 39 | + |
| 40 | +-#ifdef HAVE_SIGSETJMP |
| 41 | ++#ifdef USE_ALARM_TIMEOUT |
| 42 | + /* Beware this is a global and unique instance. This is used to store the |
| 43 | + return address that we can jump back to from inside a signal handler. This |
| 44 | + is not thread-safe stuff. */ |
| 45 | + sigjmp_buf curl_jmpenv; |
| 46 | ++curl_simple_lock curl_jmpenv_lock; |
| 47 | + #endif |
| 48 | + |
| 49 | + /* lookup address, returns entry if found and not stale */ |
| 50 | +@@ -640,7 +648,6 @@ enum resolve_t Curl_resolv(struct Curl_easy *data, |
| 51 | + static |
| 52 | + void alarmfunc(int sig) |
| 53 | + { |
| 54 | +- /* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */ |
| 55 | + (void)sig; |
| 56 | + siglongjmp(curl_jmpenv, 1); |
| 57 | + } |
| 58 | +@@ -720,6 +727,8 @@ enum resolve_t Curl_resolv_timeout(struct Curl_easy *data, |
| 59 | + This should be the last thing we do before calling Curl_resolv(), |
| 60 | + as otherwise we'd have to worry about variables that get modified |
| 61 | + before we invoke Curl_resolv() (and thus use "volatile"). */ |
| 62 | ++ curl_simple_lock_lock(&curl_jmpenv_lock); |
| 63 | ++ |
| 64 | + if(sigsetjmp(curl_jmpenv, 1)) { |
| 65 | + /* this is coming from a siglongjmp() after an alarm signal */ |
| 66 | + failf(data, "name lookup timed out"); |
| 67 | +@@ -788,6 +797,8 @@ clean_up: |
| 68 | + #endif |
| 69 | + #endif /* HAVE_SIGACTION */ |
| 70 | + |
| 71 | ++ curl_simple_lock_unlock(&curl_jmpenv_lock); |
| 72 | ++ |
| 73 | + /* switch back the alarm() to either zero or to what it was before minus |
| 74 | + the time we spent until now! */ |
| 75 | + if(prev_alarm) { |
| 76 | +-- |
| 77 | +2.39.4 |
| 78 | + |
0 commit comments