-
Notifications
You must be signed in to change notification settings - Fork 2.2k
(PUP-9312) Whitelist registry reads for Windows package providers #7266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PUP-9312) Whitelist registry reads for Windows package providers #7266
Conversation
- When failing to retrieve a registry value, the API called to read the pointer of the name of the subkey was used improperly, resulting in a messsage like: Error: Could not run: wrong number of arguments (given 0, expected 1..3) C:/source/puppet-PUP-9312/lib/puppet/util/windows/api_types.rb:56:in `read_wide_string' Fix this, so the message is correctly emitted instead like: Error: Could not run: Failed to read registry value QuietDisplayName at Software\Microsoft\Windows\CurrentVersion\Uninstall\7-Zip: The operation completed successfully.
CLA signed by all contributors. |
508f8db
to
bd2b5f2
Compare
@Iristyle I've updated the PR. Due the error handling in
I also added a simple test for the I don't think this requires any test changes for the package provider code, only the registry portions. |
CLA signed by all contributors. |
@glennsarti so I was intentionally trying to avoid enumerating the keys given there's an API for retrieving by name - this ends up adding a fair amount more code. I initially looked at doing something like you ended up with, but decided on the direction in my PR. I'll take a look at your concern about |
- Previous error handling for Win32 registry API calls were, in some cases, relying on FFI to call GetLastError behind the scenes when raising a new Puppet::Util::Windows::Error. However, Registry API calls do not use GetLastError and instead return error codes directly from their API calls. " If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. " The above is what Puppet::Util::Windows::Error does when given an explicit error code. - This fixes multiple problems with being able to inspect actual error codes from raised exceptions. In particular, it's helpful to know when RegQueryValueExW has returned a value of "2" which is ERROR_FILE_NOT_FOUND, meaning a registry value does not exist with the given name. This is important for the next commit.
6397070
to
c3163fd
Compare
vals[name] = data | ||
rescue Puppet::Util::Windows::Error => e | ||
# ignore missing names, but raise other errors | ||
raise e unless e.code == Puppet::Util::Windows::Error::ERROR_FILE_NOT_FOUND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!
- Previously, the Windows package provider would enumerate all registry values affiliated with a given product. Products are enumerated under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall Where each individual product resides in a subkey, like 7-Zip This could result in reading quite a bit of extraneous data. - In reality, there are only 9 total key values that the package provider is interested in for either MSI or EXE packages, so whitelist those values when enumerating for a given product. - This also fixes an issue where some products may install bad data into registry values (one such product stores binary data inside of a REG_SZ which breaks Puppets abiliy to interpret the value as a string). While this is really the fault of the product and not of Puppet, Puppet must be resilient to such bad data.
c3163fd
to
65d1355
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mergin time
Previously, the Windows package provider would enumerate all
registry values affiliated with a given product.
Products are enumerated under
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Where each individual product resides in a subkey, like 7-Zip
This could result in reading quite a bit of extraneous data.
In reality, there are only 9 key values that the package provider
is interested in, so whitelist those values when enumerating
for a given product.
This also fixes an issue where some products may install bad data
into registry values (one such product stores binary data inside
of a REG_SZ which breaks Puppets abiliy to interpret the value
as a string).
While this is really the fault of the product and not of Puppet,
Puppet must be resilient to such bad data.
Alternate approach to #7244