]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/http.cpp
Rewind the input stream after failing to load image from it.
[wxWidgets.git] / src / common / http.cpp
index c4a6c05dce6bb59eb03d4f738f0d9a330a628bb0..4af87f6d241aab34f87db36a86ee31e0d7070302 100644 (file)
@@ -251,16 +251,14 @@ bool wxHTTP::Connect(const wxString& host, unsigned short port)
     wxIPV4address *addr;
 
     if (m_addr) {
-        delete m_addr;
-        m_addr = NULL;
+        wxDELETE(m_addr);
         Close();
     }
 
     m_addr = addr = new wxIPV4address();
 
     if (!addr->Hostname(host)) {
-        delete m_addr;
-        m_addr = NULL;
+        wxDELETE(m_addr);
         m_lastError = wxPROTO_NETERR;
         return false;
     }
@@ -348,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;
     }