-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use registry to get timezone #52046
Use registry to get timezone #52046
Conversation
Reverts PR 51095 Checks for null characters
@afischer-opentext-com @arizvisa This should take care of the issue with null values. Please let me know if this solves the issues you are having. |
Doesn't it make sense to use the command as a fallback in case the registry lookup fails? That way we always would have a legit result. |
The transition to The transition to |
Yeah despite this specifically being related to a timezone, really it's just the semantics of the registry apis that's confusing. Fetching the Timezone from the registry is probably safe. The oversight is that Windows allows you to write arbitrary data to any the registry types. So types such as REG_SZ (and even REG_DWORD), lets you write anything you want (its parameters are a pointer to your data and a length) due to the type really just being an enumeration and not a constraint. The REG_SZ parameter even mentions that it must be null-terminated in the api documentation. So the proper workflow is, if you want to read arbitrary data from the registry. There's no need to process anything. However.. if you want to read a "string" from the registry, it is up to you to terminate it at the null byte (unless your programming language already does it for you). |
Ftr, with the prior comment this implies that any place that a string is intended to be fetched from the registry has the potential to include null bytes at the end. As twangboy mentioned, this manifests itself in the timezone on some versions of Windows which can include more than one trailng null byte. Actually, after posting the prior comment I went to check the size of the timezone which turns out to be a common/constant size. I'm willing to bet the code that Windows was using for writing the timezone looks like:
|
What does this PR do?
Uses the registry to get the timezone (reverts #51095)
Handles null characters in the registry.
Adds tests to handle null characters in the registry.
Registry is faster than shelling out commands:
Since this is used for grains and is run often we need this to be fast.
What issues does this PR fix or reference?
#50667
#51940
Tests written?
Yes
Commits signed with GPG?
Yes