-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(MODULES-1921) Ruby registry writes corrupt string
- The Ruby implementation of write is buggy at : https://github.com/ruby/ruby/blob/v2_1_6/ext/win32/lib/win32/registry.rb#L727-L748 When writing a REG_MULTI_SZ, the MSDN documentation for RegSetValueEx https://msdn.microsoft.com/en-us/library/windows/desktop/ms724923(v=vs.85).aspx states that for the lpData parameter that "With the REG_MULTI_SZ data type, the string must be terminated with two null characters." It further states for the cbData parameter that "The size of the information pointed to by the lpData parameter, in bytes. If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must include the size of the terminating null character or characters." Looking at the implementation, we can see that the length for a REG_MULTI_SZ is calculated properly, but the second terminating NULL is never written to the string. The REG_SZ and REG_EXPAND_SZ handling is affected by the same issue as the length calculation takes into account a terminator that is not present. This can lead to intermittent memory corruption based on what's present in the last 2 bytes of a given buffer. There is no guarantee that this memory is zeroed out prior to use. Unfortunately, the only way to work around this issue is to do a reimplementation of write that terminates the array of bytes properly (with a double NULL terminator that is UTF16-LE). Note that the end of the byte array should be 4 NULL bytes like [0, 0, 0, 0] - Add additional specs for writing and destroying all of the supported registry types. - Note: No support has been added for REG_DWORD_BIG_ENDIAN
- Loading branch information
Showing
3 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters