forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
From 8e21b1a05f3c0ee098dbcb6c3d84cb61f102a122 Mon Sep 17 00:00:00 2001 | ||
From: Daniel Stenberg <daniel@haxx.se> | ||
Date: Mon, 8 May 2023 14:33:54 +0200 | ||
Subject: [PATCH] libssh2: free fingerprint better | ||
|
||
Reported-by: Wei Chong Tan | ||
Closes #11088 | ||
--- | ||
lib/vssh/libssh2.c | 3 +-- | ||
1 file changed, 1 insertion(+), 2 deletions(-) | ||
|
||
diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c | ||
index bfcc94e160178..dd39a844c646b 100644 | ||
--- a/lib/vssh/libssh2.c | ||
+++ b/lib/vssh/libssh2.c | ||
@@ -728,11 +728,10 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data) | ||
*/ | ||
if((pub_pos != b64_pos) || | ||
strncmp(fingerprint_b64, pubkey_sha256, pub_pos)) { | ||
- free(fingerprint_b64); | ||
- | ||
failf(data, | ||
"Denied establishing ssh session: mismatch sha256 fingerprint. " | ||
"Remote %s is not equal to %s", fingerprint_b64, pubkey_sha256); | ||
+ free(fingerprint_b64); | ||
state(data, SSH_SESSION_FREE); | ||
sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; | ||
return sshc->actualcode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
From 13718030ad4b3209a7583b4f27f683cd3a6fa5f2 Mon Sep 17 00:00:00 2001 | ||
From: Harry Sintonen <sintonen@iki.fi> | ||
Date: Tue, 25 Apr 2023 09:22:26 +0200 | ||
Subject: [PATCH] hostip: add locks around use of global buffer for alarm() | ||
|
||
When building with the sync name resolver and timeout ability we now | ||
require thread-safety to be present to enable it. | ||
|
||
Closes #11030 | ||
--- | ||
lib/hostip.c | 19 +++++++++++++++---- | ||
1 file changed, 15 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/lib/hostip.c b/lib/hostip.c | ||
index 2381290fdd43e..e410cda69ae6e 100644 | ||
--- a/lib/hostip.c | ||
+++ b/lib/hostip.c | ||
@@ -70,12 +70,19 @@ | ||
#include <SystemConfiguration/SCDynamicStoreCopySpecific.h> | ||
#endif | ||
|
||
-#if defined(CURLRES_SYNCH) && \ | ||
- defined(HAVE_ALARM) && defined(SIGALRM) && defined(HAVE_SIGSETJMP) | ||
+#if defined(CURLRES_SYNCH) && \ | ||
+ defined(HAVE_ALARM) && \ | ||
+ defined(SIGALRM) && \ | ||
+ defined(HAVE_SIGSETJMP) && \ | ||
+ defined(GLOBAL_INIT_IS_THREADSAFE) | ||
/* alarm-based timeouts can only be used with all the dependencies satisfied */ | ||
#define USE_ALARM_TIMEOUT | ||
#endif | ||
|
||
+#ifdef USE_ALARM_TIMEOUT | ||
+#include "easy_lock.h" | ||
+#endif | ||
+ | ||
#define MAX_HOSTCACHE_LEN (255 + 7) /* max FQDN + colon + port number + zero */ | ||
|
||
/* | ||
@@ -254,11 +261,12 @@ void Curl_hostcache_prune(struct Curl_easy *data) | ||
Curl_share_unlock(data, CURL_LOCK_DATA_DNS); | ||
} | ||
|
||
-#ifdef HAVE_SIGSETJMP | ||
+#ifdef USE_ALARM_TIMEOUT | ||
/* Beware this is a global and unique instance. This is used to store the | ||
return address that we can jump back to from inside a signal handler. This | ||
is not thread-safe stuff. */ | ||
sigjmp_buf curl_jmpenv; | ||
+curl_simple_lock curl_jmpenv_lock; | ||
#endif | ||
|
||
/* lookup address, returns entry if found and not stale */ | ||
@@ -832,7 +840,6 @@ enum resolve_t Curl_resolv(struct Curl_easy *data, | ||
static | ||
void alarmfunc(int sig) | ||
{ | ||
- /* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */ | ||
(void)sig; | ||
siglongjmp(curl_jmpenv, 1); | ||
} | ||
@@ -912,6 +919,8 @@ enum resolve_t Curl_resolv_timeout(struct Curl_easy *data, | ||
This should be the last thing we do before calling Curl_resolv(), | ||
as otherwise we'd have to worry about variables that get modified | ||
before we invoke Curl_resolv() (and thus use "volatile"). */ | ||
+ curl_simple_lock_lock(&curl_jmpenv_lock); | ||
+ | ||
if(sigsetjmp(curl_jmpenv, 1)) { | ||
/* this is coming from a siglongjmp() after an alarm signal */ | ||
failf(data, "name lookup timed out"); | ||
@@ -980,6 +989,8 @@ enum resolve_t Curl_resolv_timeout(struct Curl_easy *data, | ||
#endif | ||
#endif /* HAVE_SIGACTION */ | ||
|
||
+ curl_simple_lock_unlock(&curl_jmpenv_lock); | ||
+ | ||
/* switch back the alarm() to either zero or to what it was before minus | ||
the time we spent until now! */ | ||
if(prev_alarm) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
From 199f2d440d8659b42670c1b796220792b01a97bf Mon Sep 17 00:00:00 2001 | ||
From: Daniel Stenberg <daniel@haxx.se> | ||
Date: Mon, 24 Apr 2023 21:07:02 +0200 | ||
Subject: [PATCH] hostcheck: fix host name wildcard checking | ||
|
||
The leftmost "label" of the host name can now only match against single | ||
'*'. Like the browsers have worked for a long time. | ||
|
||
- extended unit test 1397 for this | ||
- move some SOURCE variables from unit/Makefile.am to unit/Makefile.inc | ||
|
||
Reported-by: Hiroki Kurosawa | ||
Closes #11018 | ||
--- | ||
lib/vtls/hostcheck.c | 50 +++++++-------- | ||
tests/data/test1397 | 10 ++- | ||
tests/unit/unit1397.c | 134 ++++++++++++++++++++++++---------------- | ||
5 files changed, 202 insertions(+), 180 deletions(-) | ||
|
||
diff --git a/lib/vtls/hostcheck.c b/lib/vtls/hostcheck.c | ||
index e827dc58f378c..d061c6356f97f 100644 | ||
--- a/lib/vtls/hostcheck.c | ||
+++ b/lib/vtls/hostcheck.c | ||
@@ -71,7 +71,12 @@ static bool pmatch(const char *hostname, size_t hostlen, | ||
* apparent distinction between a name and an IP. We need to detect the use of | ||
* an IP address and not wildcard match on such names. | ||
* | ||
+ * Only match on "*" being used for the leftmost label, not "a*", "a*b" nor | ||
+ * "*b". | ||
+ * | ||
* Return TRUE on a match. FALSE if not. | ||
+ * | ||
+ * @unittest: 1397 | ||
*/ | ||
|
||
static bool hostmatch(const char *hostname, | ||
@@ -79,53 +84,42 @@ static bool hostmatch(const char *hostname, | ||
const char *pattern, | ||
size_t patternlen) | ||
{ | ||
- const char *pattern_label_end, *wildcard, *hostname_label_end; | ||
- size_t prefixlen, suffixlen; | ||
+ const char *pattern_label_end; | ||
|
||
- /* normalize pattern and hostname by stripping off trailing dots */ | ||
+ DEBUGASSERT(pattern); | ||
DEBUGASSERT(patternlen); | ||
+ DEBUGASSERT(hostname); | ||
+ DEBUGASSERT(hostlen); | ||
+ | ||
+ /* normalize pattern and hostname by stripping off trailing dots */ | ||
if(hostname[hostlen-1]=='.') | ||
hostlen--; | ||
if(pattern[patternlen-1]=='.') | ||
patternlen--; | ||
|
||
- wildcard = memchr(pattern, '*', patternlen); | ||
- if(!wildcard) | ||
+ if(strncmp(pattern, "*.", 2)) | ||
return pmatch(hostname, hostlen, pattern, patternlen); | ||
|
||
/* detect IP address as hostname and fail the match if so */ | ||
- if(Curl_host_is_ipnum(hostname)) | ||
+ else if(Curl_host_is_ipnum(hostname)) | ||
return FALSE; | ||
|
||
/* We require at least 2 dots in the pattern to avoid too wide wildcard | ||
match. */ | ||
pattern_label_end = memchr(pattern, '.', patternlen); | ||
if(!pattern_label_end || | ||
- (memrchr(pattern, '.', patternlen) == pattern_label_end) || | ||
- strncasecompare(pattern, "xn--", 4)) | ||
+ (memrchr(pattern, '.', patternlen) == pattern_label_end)) | ||
return pmatch(hostname, hostlen, pattern, patternlen); | ||
- | ||
- hostname_label_end = memchr(hostname, '.', hostlen); | ||
- if(!hostname_label_end) | ||
- return FALSE; | ||
else { | ||
- size_t skiphost = hostname_label_end - hostname; | ||
- size_t skiplen = pattern_label_end - pattern; | ||
- if(!pmatch(hostname_label_end, hostlen - skiphost, | ||
- pattern_label_end, patternlen - skiplen)) | ||
- return FALSE; | ||
+ const char *hostname_label_end = memchr(hostname, '.', hostlen); | ||
+ if(hostname_label_end) { | ||
+ size_t skiphost = hostname_label_end - hostname; | ||
+ size_t skiplen = pattern_label_end - pattern; | ||
+ return pmatch(hostname_label_end, hostlen - skiphost, | ||
+ pattern_label_end, patternlen - skiplen); | ||
+ } | ||
} | ||
- /* The wildcard must match at least one character, so the left-most | ||
- label of the hostname is at least as large as the left-most label | ||
- of the pattern. */ | ||
- if(hostname_label_end - hostname < pattern_label_end - pattern) | ||
- return FALSE; | ||
- | ||
- prefixlen = wildcard - pattern; | ||
- suffixlen = pattern_label_end - (wildcard + 1); | ||
- return strncasecompare(pattern, hostname, prefixlen) && | ||
- strncasecompare(wildcard + 1, hostname_label_end - suffixlen, | ||
- suffixlen) ? TRUE : FALSE; | ||
+ return FALSE; | ||
} | ||
|
||
/* | ||
diff --git a/tests/data/test1397 b/tests/data/test1397 | ||
index 84f962abebee3..f31b2c2a3f330 100644 | ||
--- a/tests/data/test1397 | ||
+++ b/tests/data/test1397 | ||
@@ -2,8 +2,7 @@ | ||
<info> | ||
<keywords> | ||
unittest | ||
-ssl | ||
-wildcard | ||
+Curl_cert_hostcheck | ||
</keywords> | ||
</info> | ||
|
||
@@ -16,9 +15,8 @@ none | ||
<features> | ||
unittest | ||
</features> | ||
- <name> | ||
-Check wildcard certificate matching function Curl_cert_hostcheck | ||
- </name> | ||
+<name> | ||
+Curl_cert_hostcheck unit tests | ||
+</name> | ||
</client> | ||
- | ||
</testcase> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters