From: Vadim Zeitlin Date: Fri, 25 Jun 2010 09:42:21 +0000 (+0000) Subject: Fix posting of binary data using wxHTTP. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/658e62e493c1da835ba9b67f7ce52cfa4e5ed010 Fix posting of binary data using wxHTTP. Don't use mbc_str() which can fail to convert contents of the string created using wxString::From8BitData(). Use To8BitData() instead. This fixes posting of binary data via HTTP using binary content transfer encoding. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64728 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index ebca103e84..730996fbaa 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -452,6 +452,7 @@ All: - Added wxMessageQueue::Clear(). - Added wxConfig::Read(float *) overload (Terry Farnham). - Always use decimal point (and not the current locale separator) in wxConfig. +- Fix posting of binary data using wxHTTP (Catalin Raceanu). Unix: diff --git a/src/common/http.cpp b/src/common/http.cpp index 9a4833595e..4af87f6d24 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -346,7 +346,17 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req) Write("\r\n", 2); if ( req == wxHTTP_POST ) { - Write(m_post_buf.mbc_str(), m_post_buf.Len()); + // Post data can be arbitrary binary data when the "binary" content + // transfer encoding is used so don't assume it's ASCII only or + // NUL-terminated. + { + const wxScopedCharBuffer buf(m_post_buf.To8BitData()); + Write(buf, buf.length()); + } // delete the buffer before modifying the string it points to, it + // wouldn't really be a problem here even if we didn't do this + // because we won't use this buffer again but this will avoid any + // nasty surprises in the future if this code changes + m_post_buf = wxEmptyString; }