Search

CHttpFile::QueryInfo() returns "corrupted" CStrings with invalid lengths. by ijprest

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 773448
Opened: 12/4/2012 12:15:00 PM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
The implementation of the CString form of CHttpFile::QueryInfo() calls HttpQueryInfo to determine how big a buffer to allocate, which is always reported in bytes.

Since CHttpFile::QueryInfo() neglects to divide by sizeof(TCHAR), it ends up allocating a buffer twice as big as necessary in UNICODE builds.

When CHttpFile::QueryInfo() subsequently calls ReleaseBuffer() on the CString, it again specifies the incorrect size. As a result, the CString thinks it's bigger than it actually is, and cannot be used normally (e.g., in CString contenation scenarios).
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

The following code snippet demonstrates the problem. (Compile w/UNICODE enabled)
---------------
CInternetSession session;
CHttpConnection* pConnection = session.GetHttpConnection(L"www.microsoft.com");
CHttpFile* pFile = pConnection->OpenRequest(L"GET", L"/");
pFile->SendRequest();

CString str;
pFile->QueryInfo(HTTP_QUERY_STATUS_TEXT, str);

CString message = CString(L"The status code '") + str + CString(L"' was received from the server.");
int length = str.GetLength();
------------------------

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

message == "The status code 'OK"
length == 4

Expected results

message == "The status code 'OK' was received from the server."
length == 2
File Attachments
File Name Submitted By Submitted On File Size  
httpfiletest.zip 12/5/2012 16 KB
Sign in to post a comment.
Posted by Microsoft on 12/7/2012 at 12:54 AM
Hi ijprest, thanks for your response, we have received your demo project.
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by ijprest on 12/5/2012 at 9:22 AM
I have attached a demo project (I think).
Posted by Microsoft on 12/4/2012 at 11:02 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting a demo project. Please submit this information to us within 3 business days. We look forward to hearing from you with this information.
Posted by Microsoft on 12/4/2012 at 12:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.