[Asterisk-code-review] func_curl.c: Prevent crash when using CURLOPT(httpheader) (asterisk[13])

Sean Bright asteriskteam at digium.com
Fri Sep 18 08:14:05 CDT 2020


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14930 )


Change subject: func_curl.c: Prevent crash when using CURLOPT(httpheader)
......................................................................

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
---
M funcs/func_curl.c
1 file changed, 4 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/30/14930/1

diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index b6b6181..3016cc8 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -705,9 +705,10 @@
 		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';

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14930
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I8b4ab34038156dfba613030a45f10e932d2e992d
Gerrit-Change-Number: 14930
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200918/272aa969/attachment.html>


More information about the asterisk-code-review mailing list