Closed Bug 1229804 Opened 10 years ago Closed 10 years ago

Incorrect string length specified in Windows sandbox logging.

Categories

(Core :: Security: Process Sandboxing, defect)

All
Windows
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla45
Tracking Status
firefox45 --- fixed

People

(Reporter: bobowen, Assigned: bobowen)

Details

Attachments

(1 file)

It seems that the Length in UNICODE_STRING that I use is in bytes, even though the buffer pointer in the same structure is effectively a wchar_t* (which is always 2 bytes on Windows).
Attachment #8694797 - Flags: review?(tabraldes)
Comment on attachment 8694797 [details] [diff] [review] Use the correct string length in Windows sandbox logging Review of attachment 8694797 [details] [diff] [review]: ----------------------------------------------------------------- ::: security/sandbox/chromium-shim/sandbox/win/sandboxLogging.cpp @@ +65,5 @@ > { > if (sLogFunction) { > // Skip an extra frame to allow for this function. > LogBlocked(aFunctionName, > + base::WideToUTF8(std::wstring(aContext, aLengthInBytes / sizeof(wchar_t))).c_str(), I think we could take advantage of the `std::wstring(const_pointer _First, const_pointer _Last)` constructor [1] to rewrite this instead as `base::WideToUTF8(std::wstring(aContext, aContext + aLengthInBytes)).c_str(),` [1] https://msdn.microsoft.com/en-us/library/y22b7w38.aspx
Attachment #8694797 - Flags: review?(tabraldes) → review+
(In reply to Tim Abraldes [:TimAbraldes] [:tabraldes] from comment #3) > Comment on attachment 8694797 [details] [diff] [review] > Use the correct string length in Windows sandbox logging > > Review of attachment 8694797 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: security/sandbox/chromium-shim/sandbox/win/sandboxLogging.cpp > @@ +65,5 @@ > > { > > if (sLogFunction) { > > // Skip an extra frame to allow for this function. > > LogBlocked(aFunctionName, > > + base::WideToUTF8(std::wstring(aContext, aLengthInBytes / sizeof(wchar_t))).c_str(), > > I think we could take advantage of the `std::wstring(const_pointer _First, > const_pointer _Last)` constructor [1] to rewrite this instead as > `base::WideToUTF8(std::wstring(aContext, aContext + > aLengthInBytes)).c_str(),` > > [1] https://msdn.microsoft.com/en-us/library/y22b7w38.aspx There might be an off-by-one error in this suggestion. It might need to be `aContext + aLengthInBytes - 1`. I'm not sure from the documentation that I've read
Thanks Tim. (In reply to Tim Abraldes [:TimAbraldes] [:tabraldes] from comment #3) > > + base::WideToUTF8(std::wstring(aContext, aLengthInBytes / sizeof(wchar_t))).c_str(), > > I think we could take advantage of the `std::wstring(const_pointer _First, > const_pointer _Last)` constructor [1] to rewrite this instead as > `base::WideToUTF8(std::wstring(aContext, aContext + > aLengthInBytes)).c_str(),` But aContext is a wchar_t* (wchar_t is 2 bytes on Windows), so with pointer arithmetic, as the length is in bytes _Last would be at a point double the length of the string.
(In reply to Bob Owen (:bobowen) from comment #5) > Thanks Tim. > > (In reply to Tim Abraldes [:TimAbraldes] [:tabraldes] from comment #3) > > > > + base::WideToUTF8(std::wstring(aContext, aLengthInBytes / sizeof(wchar_t))).c_str(), > > > > I think we could take advantage of the `std::wstring(const_pointer _First, > > const_pointer _Last)` constructor [1] to rewrite this instead as > > `base::WideToUTF8(std::wstring(aContext, aContext + > > aLengthInBytes)).c_str(),` > > But aContext is a wchar_t* (wchar_t is 2 bytes on Windows), so with pointer > arithmetic, as the length is in bytes _Last would be at a point double the > length of the string. Ah, good point. We'd have to do some casting or do the exact same math for that approach to work.
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: