Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Use registry to get timezone #52046
What does this PR do?
Uses the registry to get the timezone (reverts #51095)
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?
Commits signed with GPG?
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: