From 2dd8049aeffab90b0ced3ccdff3b67371b320a3b Mon Sep 17 00:00:00 2001 From: derrod Date: Sun, 29 Aug 2021 01:25:14 +0200 Subject: [PATCH] UI: Add postDataSize option to GetRemoteText In order to be able to POST binary data that may contain NULL-bytes we must manually specify the size of the array, otherwise cURL will fall back to `strlen()`. --- UI/remote-text.cpp | 8 +++++++- UI/remote-text.hpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/UI/remote-text.cpp b/UI/remote-text.cpp index 50ed4f43c..d4991abe8 100644 --- a/UI/remote-text.cpp +++ b/UI/remote-text.cpp @@ -123,7 +123,8 @@ bool GetRemoteFile(const char *url, std::string &str, std::string &error, long *responseCode, const char *contentType, std::string request_type, const char *postData, std::vector extraHeaders, - std::string *signature, int timeoutSec, bool fail_on_error) + std::string *signature, int timeoutSec, bool fail_on_error, + int postDataSize) { vector header_in_list; char error_in[CURL_ERROR_SIZE]; @@ -196,6 +197,11 @@ bool GetRemoteFile(const char *url, std::string &str, std::string &error, } } if (postData) { + if (postDataSize > 0) { + curl_easy_setopt(curl.get(), + CURLOPT_POSTFIELDSIZE, + (long)postDataSize); + } curl_easy_setopt(curl.get(), CURLOPT_POSTFIELDS, postData); } diff --git a/UI/remote-text.hpp b/UI/remote-text.hpp index becb9a5f8..66113c8c0 100644 --- a/UI/remote-text.hpp +++ b/UI/remote-text.hpp @@ -69,4 +69,4 @@ bool GetRemoteFile( std::string request_type = "", const char *postData = nullptr, std::vector extraHeaders = std::vector(), std::string *signature = nullptr, int timeoutSec = 0, - bool fail_on_error = true); + bool fail_on_error = true, int postDataSize = 0);