From 28c88e8fe2c0edf26821a998681deed6741564c7 Mon Sep 17 00:00:00 2001
From: Sean Bright <sean.bright@gmail.com>
Date: Fri, 18 Sep 2020 09:09:59 -0400
Subject: [PATCH] func_curl.c: Prevent crash when using CURLOPT(httpheader)

Because we use shared thread-local cURL instances, we need to ensure
that the state of the cURL instance is correct before each invocation.

In the case of custom headers, we were not resetting cURL's internal
HTTP header pointer which could result in a crash if subsequent
requests do not configure custom headers.

ASTERISK-29085 #close

Change-Id: I8b4ab34038156dfba613030a45f10e932d2e992d
---
 funcs/func_curl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index 3e09d1cbe7..cc3b195f28 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -721,9 +721,10 @@ static int acf_curl_helper(struct ast_channel *chan, struct curl_args *args)
 		curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, args->postdata);
 	}
 
-	if (headers) {
-		curl_easy_setopt(*curl, CURLOPT_HTTPHEADER, headers);
-	}
+	/* Always assign the headers - even when NULL - in case we had
+	 * custom headers the last time we used this shared cURL
+	 * instance */
+	curl_easy_setopt(*curl, CURLOPT_HTTPHEADER, headers);
 
 	/* Temporarily assign a buffer for curl to write errors to. */
 	curl_errbuf[0] = curl_errbuf[CURL_ERROR_SIZE] = '\0';
-- 
GitLab