[mod_http_cache] Crash on HTTP GET with generated AWS v4 signature
Co-authored-by: Miguel Gonzalez <maggonzz@gmail.com>
This commit is contained in:
parent
b7b83db66d
commit
0f7ba14333
|
@ -291,6 +291,11 @@ SWITCH_MOD_DECLARE(switch_curl_slist_t *) aws_s3_append_headers(
|
||||||
switch_aws_s3_profile aws_s3_profile;
|
switch_aws_s3_profile aws_s3_profile;
|
||||||
char* url_dup;
|
char* url_dup;
|
||||||
|
|
||||||
|
if (!query_string) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required arg query_string.\n");
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
// Get bucket and object name from url
|
// Get bucket and object name from url
|
||||||
switch_strdup(url_dup, url);
|
switch_strdup(url_dup, url);
|
||||||
parse_url(url_dup, profile->base_domain, "s3", &aws_s3_profile.bucket, &aws_s3_profile.object);
|
parse_url(url_dup, profile->base_domain, "s3", &aws_s3_profile.bucket, &aws_s3_profile.object);
|
||||||
|
|
|
@ -1099,6 +1099,8 @@ static switch_status_t http_get(url_cache_t *cache, http_profile_t *profile, cac
|
||||||
long httpRes = 0;
|
long httpRes = 0;
|
||||||
int start_time_ms = switch_time_now() / 1000;
|
int start_time_ms = switch_time_now() / 1000;
|
||||||
switch_CURLcode curl_status = CURLE_UNKNOWN_OPTION;
|
switch_CURLcode curl_status = CURLE_UNKNOWN_OPTION;
|
||||||
|
char *query_string = NULL;
|
||||||
|
char *full_url = NULL;
|
||||||
|
|
||||||
/* set up HTTP GET */
|
/* set up HTTP GET */
|
||||||
get_data.fd = 0;
|
get_data.fd = 0;
|
||||||
|
@ -1110,7 +1112,14 @@ static switch_status_t http_get(url_cache_t *cache, http_profile_t *profile, cac
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile && profile->append_headers_ptr) {
|
if (profile && profile->append_headers_ptr) {
|
||||||
headers = profile->append_headers_ptr(profile, headers, "GET", 0, "", url->url, 0, NULL);
|
headers = profile->append_headers_ptr(profile, headers, "GET", 0, "", url->url, 0, &query_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query_string) {
|
||||||
|
full_url = switch_mprintf("%s?%s", url->url, query_string);
|
||||||
|
free(query_string);
|
||||||
|
} else {
|
||||||
|
switch_strdup(full_url, url->url);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_handle = switch_curl_easy_init();
|
curl_handle = switch_curl_easy_init();
|
||||||
|
@ -1123,7 +1132,7 @@ static switch_status_t http_get(url_cache_t *cache, http_profile_t *profile, cac
|
||||||
if (headers) {
|
if (headers) {
|
||||||
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
|
||||||
}
|
}
|
||||||
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, get_data.url->url);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, full_url);
|
||||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, get_file_callback);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, get_file_callback);
|
||||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &get_data);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &get_data);
|
||||||
switch_curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, get_header_callback);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, get_header_callback);
|
||||||
|
@ -1178,6 +1187,7 @@ static switch_status_t http_get(url_cache_t *cache, http_profile_t *profile, cac
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
||||||
|
switch_safe_free(full_url);
|
||||||
if (headers) {
|
if (headers) {
|
||||||
switch_curl_slist_free_all(headers);
|
switch_curl_slist_free_all(headers);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue