fix(win): remove MAX_PATH dependency#135
Conversation
| auto path_buffer = | ||
| base::HeapArray<wchar_t>::Uninit(path_length_bytes / sizeof(wchar_t)); |
There was a problem hiding this comment.
Potential bug: The buffer allocation for path_buffer uses integer division on path_length_bytes without validating its divisibility by sizeof(wchar_t), potentially creating an undersized buffer.
-
Description: In
HandleAddAttachmentV2andHandleRemoveAttachmentV2, the buffer for an attachment path is allocated usingpath_length_bytes / sizeof(wchar_t). This calculation uses integer division, which truncates the result. If the server receives apath_length_bytesvalue from a client that is not evenly divisible bysizeof(wchar_t)(2 bytes), the allocatedpath_bufferwill be smaller thanpath_length_bytes. The subsequent call toLoggingReadFileExactlyattempts to read the fullpath_length_bytesinto this undersized buffer, causing a heap buffer overflow. This can lead to memory corruption or a crash of the exception handler server. -
Suggested fix: Before allocating the buffer in
HandleAddAttachmentV2andHandleRemoveAttachmentV2, add a check to validate thatpath_length_bytesis evenly divisible bysizeof(wchar_t). If the check fails, log an error and return early to prevent the allocation and subsequent buffer overflow.
severity: 0.85, confidence: 0.95
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
While we can be sure that our untampered client will send bytes that are multiples of wchar_t, since it is IPC, we should protect against malicious or corrupted input. I will add further validation of the incoming message.
This is meant to be merged and released with getsentry/sentry-native#1413.
It removes
MAX_PATHdependencies where it makes sense (similar in intent to getsentry/breakpad#43). In particular,MAX_PATHwill no longer be used forGetModuleFileName()GetFileInformationByHandleEx()While the latter two are only changes in terms of heap buffer handling, the first item required an adaptation of the IPC protocol. There were two options:
I chose the latter option because it introduces the least amount of change with respect to upstream maintenance.