(PUP-5640)(PUP-5591) Fix Win32 Registry Reads which cause errors#4534
(PUP-5640)(PUP-5591) Fix Win32 Registry Reads which cause errors#4534glennsarti wants to merge 1 commit intopuppetlabs:stablefrom
Conversation
There was a problem hiding this comment.
I tried using REG.EXE and Ruby API calls but they all guarded against invalid values. Eventually found I could craft a .REG file to make a bad value. Need to test on 2008 though
|
Does this supersede my initial PR? |
315654a to
9f33bcd
Compare
|
That is the intent yes. I wanted to get it working before I commented on your PR |
9f33bcd to
d573631
Compare
There was a problem hiding this comment.
Is it always an IndexError?
There was a problem hiding this comment.
Yes. The underlying call is to FFI MemoryPointer get_bytes
http://www.rubydoc.info/github/ffi/ffi/FFI%2FAbstractMemory%3Aget_bytes
"(IndexError) — if length is too great"
There was a problem hiding this comment.
FFI impl is https://github.com/ffi/ffi/blob/master/ext/ffi_c/AbstractMemory.c#L450-L472
Looks like IndexError is indeed the only thing that we can deal with...
03cbc45 to
0ad1798
Compare
|
This PR supersedes #4488 |
ef1b0d7 to
34a7766
Compare
There was a problem hiding this comment.
Puppet already has temp file helpers... they track the file, and later clean up afterwards.
https://github.com/puppetlabs/puppet/blob/master/spec/lib/puppet_spec/files.rb#L27-L37
I wonder if we can do this without files and calling out to regedit.exe though
There was a problem hiding this comment.
I will look at using the helper class instead of the current method.
I tried creating invalid values using API calls, WMI and REG.EXE and they all protected me from making a bad call. REGEDIT.EXE was the only method that I could find that would allow me to inject a bad DWORD. I do not believe regedit will accept STDIN so the only method left was a crafted temporary reg file to import.
|
Some of the original commit message from #4488 should probably make it into this commit message: Previously, the read method was using an older variable name when This was introduced in b46ede7 (Puppet v4.0.0). Without this fix, any registry enumerations that contain a binary |
e02cf6f to
47384ca
Compare
|
@Iristyle Bad data injection has been changed from REG.EXE to using raw Win32 API |
Without this patch applied, reading REG_BINARY or corrupted registry values would cause fatal errors to be raised and the error messages did not contain enough information for users to remediate. This commit fixes a typo in the REG_BINARY logic which was referencing a now non-existent local variable. Also, the read function now has a wrapping begin-rescue clause to catch buffer overrun error messages caused by corrupted registry values e.g. a DWORD having less than 4 bytes of data. When a corrupted registry key is found, a warning is raised stating the key name, not value name, where the value is located and returns nil for the data of the value. The tests for this class have been moved from unit to integration as they were not true unit tests and required actual read/write operations on the Windows registry. Tests for the REG_BINARY and corrupted registry values scenarios were added.
Without this patch applied, reading REG_BINARY or corrupted registry values would cause fatal errors to be raised and the error messages did not contain enough information for users to remediate. This commit fixes a typo in the REG_BINARY logic which was referencing a now non-existent local variable. Also, the read function now has a wrapping begin-rescue clause to catch buffer overrun error messages caused by corrupted registry values e.g. a DWORD having less than 4 bytes of data. When a corrupted registry key is found, a warning is raised stating the key name, not value name, where the value is located and returns nil for the data of the value. The tests for this class have been moved from unit to integration as they were not true unit tests and required actual read/write operations on the Windows registry. Tests for the REG_BINARY and corrupted registry values scenarios were added.
corrupted reg values