#define CURL_SCACHE_MAGIC 0x000e1551
-#ifdef DEBUGBUILD
-/* On a debug build, we want to fail hard on scaches that
- * are not NULL, but no longer have the MAGIC touch. This gives
- * us early warning on things only discovered by valgrind otherwise. */
-#define GOOD_SCACHE(x) \
- (((x) && (x)->magic == CURL_SCACHE_MAGIC)? TRUE: \
- (DEBUGASSERT(!(x)), FALSE))
-#else
-#define GOOD_SCACHE(x) \
- ((x) && (x)->magic == CURL_SCACHE_MAGIC)
-#endif
+#define GOOD_SCACHE(x) ((x) && (x)->magic == CURL_SCACHE_MAGIC)
struct Curl_ssl_scache {
unsigned int magic;
long age;
};
+static struct Curl_ssl_scache *cf_ssl_scache_get(struct Curl_easy *data)
+{
+ struct Curl_ssl_scache *scache = NULL;
+ /* If a share is present, its ssl_scache has preference over the multi */
+ if(data->share && data->share->ssl_scache)
+ scache = data->share->ssl_scache;
+ else if(data->multi && data->multi->ssl_scache)
+ scache = data->multi->ssl_scache;
+ if(scache && !GOOD_SCACHE(scache)) {
+ failf(data, "transfer would use an invalid scache at %p, denied",
+ (void *)scache);
+ DEBUGASSERT(0);
+ return NULL;
+ }
+ return scache;
+}
+
static void cf_ssl_scache_clear_session(struct Curl_ssl_session *s)
{
if(s->sdata) {
*ppeer = NULL;
if(!GOOD_SCACHE(scache)) {
- failf(data, "cf_ssl_find_peer_by_key with BAD sache magic!");
return CURLE_BAD_FUNCTION_ARGUMENT;
}
Curl_ssl_session_destroy(s);
return CURLE_OK;
}
- if(!GOOD_SCACHE(scache)) {
- Curl_ssl_session_destroy(s);
- failf(data, "cf_scache_add_session with BAD scache magic!");
- return CURLE_BAD_FUNCTION_ARGUMENT;
- }
if(s->valid_until <= 0)
s->valid_until = now + scache->default_lifetime_secs;
const char *ssl_peer_key,
struct Curl_ssl_session *s)
{
- struct Curl_ssl_scache *scache = data->state.ssl_scache;
+ struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
CURLcode result;
DEBUGASSERT(ssl_config);
}
if(!GOOD_SCACHE(scache)) {
Curl_ssl_session_destroy(s);
- failf(data, "Curl_ssl_scache_put with BAD scache magic!");
return CURLE_BAD_FUNCTION_ARGUMENT;
}
const char *ssl_peer_key,
struct Curl_ssl_session **ps)
{
- struct Curl_ssl_scache *scache = data->state.ssl_scache;
+ struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
struct Curl_ssl_scache_peer *peer = NULL;
struct Curl_llist_node *n;
*ps = NULL;
if(!scache)
return CURLE_OK;
- if(!GOOD_SCACHE(scache)) {
- failf(data, "Curl_ssl_scache_take with BAD scache magic!");
- return CURLE_BAD_FUNCTION_ARGUMENT;
- }
Curl_ssl_scache_lock(data);
result = cf_ssl_find_peer_by_key(data, scache, ssl_peer_key, conn_config,
void *sobj,
Curl_ssl_scache_obj_dtor *sobj_free)
{
- struct Curl_ssl_scache *scache = data->state.ssl_scache;
+ struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
struct Curl_ssl_scache_peer *peer = NULL;
CURLcode result;
DEBUGASSERT(sobj);
DEBUGASSERT(sobj_free);
- if(!GOOD_SCACHE(scache)) {
- failf(data, "Curl_ssl_scache_add_obj with BAD scache magic!");
+ if(!scache) {
result = CURLE_BAD_FUNCTION_ARGUMENT;
goto out;
}
const char *ssl_peer_key,
void **sobj)
{
- struct Curl_ssl_scache *scache = data->state.ssl_scache;
+ struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
struct Curl_ssl_scache_peer *peer = NULL;
CURLcode result;
*sobj = NULL;
if(!scache)
return FALSE;
- if(!GOOD_SCACHE(scache)) {
- failf(data, "Curl_ssl_scache_get_obj with BAD scache magic!");
- return FALSE;
- }
result = cf_ssl_find_peer_by_key(data, scache, ssl_peer_key, conn_config,
&peer);
struct Curl_easy *data,
const char *ssl_peer_key)
{
- struct Curl_ssl_scache *scache = data->state.ssl_scache;
+ struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
struct Curl_ssl_scache_peer *peer = NULL;
CURLcode result;
(void)cf;
- if(!scache || !GOOD_SCACHE(scache))
+ if(!scache)
return;
Curl_ssl_scache_lock(data);
const unsigned char *shmac, size_t shmac_len,
const unsigned char *sdata, size_t sdata_len)
{
- struct Curl_ssl_scache *scache = data->state.ssl_scache;
+ struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
struct Curl_ssl_scache_peer *peer = NULL;
struct Curl_ssl_session *s = NULL;
bool locked = FALSE;
CURLcode r;
- if(!scache || !GOOD_SCACHE(scache)) {
- failf(data, "Curl_ssl_session_import with BAD scache magic!");
+ if(!scache) {
r = CURLE_BAD_FUNCTION_ARGUMENT;
goto out;
}
curl_ssls_export_cb *export_fn,
void *userptr)
{
- struct Curl_ssl_scache *scache = data->state.ssl_scache;
+ struct Curl_ssl_scache *scache = cf_ssl_scache_get(data);
struct Curl_ssl_scache_peer *peer;
struct dynbuf sbuf, hbuf;
struct Curl_llist_node *n;
return CURLE_BAD_FUNCTION_ARGUMENT;
if(!scache)
return CURLE_OK;
- if(!GOOD_SCACHE(scache)) {
- failf(data, "Curl_ssl_session_export with BAD scache magic!");
- return CURLE_BAD_FUNCTION_ARGUMENT;
- }
Curl_ssl_scache_lock(data);
--- /dev/null
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "testutil.h"
+#include "warnless.h"
+#include "memdebug.h"
+
+#define TEST_HANG_TIMEOUT 60 * 1000
+
+CURLcode test(char *URL)
+{
+ CURL *curl = NULL;
+ CURLM *multi = NULL;
+ int still_running;
+ CURLcode i = TEST_ERR_FAILURE;
+ CURLcode res = CURLE_OK;
+ CURLMsg *msg;
+
+ start_test_timing();
+
+ global_init(CURL_GLOBAL_ALL);
+
+ multi_init(multi);
+
+ easy_init(curl);
+
+ easy_setopt(curl, CURLOPT_URL, URL);
+ easy_setopt(curl, CURLOPT_HEADER, 1L);
+ /* no peer verify */
+ easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+ easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+
+ /* first, make an easy perform with the handle */
+ curl_easy_perform(curl);
+
+ /* then proceed and use it for a multi perform */
+ multi_add_handle(multi, curl);
+
+ multi_perform(multi, &still_running);
+
+ abort_on_test_timeout();
+
+ while(still_running) {
+ CURLMcode mres;
+ int num;
+ mres = curl_multi_wait(multi, NULL, 0, TEST_HANG_TIMEOUT, &num);
+ if(mres != CURLM_OK) {
+ printf("curl_multi_wait() returned %d\n", mres);
+ res = TEST_ERR_MAJOR_BAD;
+ goto test_cleanup;
+ }
+
+ abort_on_test_timeout();
+
+ multi_perform(multi, &still_running);
+
+ abort_on_test_timeout();
+ }
+
+ msg = curl_multi_info_read(multi, &still_running);
+ if(msg)
+ /* this should now contain a result code from the easy handle,
+ get it */
+ i = msg->data.result;
+
+test_cleanup:
+
+ /* undocumented cleanup sequence - type UA */
+
+ curl_multi_cleanup(multi);
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+
+ if(res)
+ i = res;
+
+ return i; /* return the final return code */
+}