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

Joshua Colp asteriskteam at digium.com
Wed Sep 23 10:05:03 CDT 2020


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14971 )

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(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved



diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index 3e09d1c..cc3b195 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -721,9 +721,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/+/14971
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 17
Gerrit-Change-Id: I8b4ab34038156dfba613030a45f10e932d2e992d
Gerrit-Change-Number: 14971
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200923/913690be/attachment.html>


More information about the asterisk-code-review mailing list