-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
fix: on Windows use UTF-8 strings instead of system default locale strings #6190
fix: on Windows use UTF-8 strings instead of system default locale strings #6190
Conversation
Thanks @Smjert for your help with the Chrome extensions test! :) |
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.
Thanks again for this effort!
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.
Last review round then I think it's good to go!
Please also remember to format the code :).
Haha! Thanks. Yeah... I just need to set up style-check validator locally. Relying on IDE works 95% of the time. |
We also have two CMake targets for this: |
merging osquery\osquery master
osquery/utils/system/windows/env.cpp
Outdated
|
||
return wstringToString(buf.data()); | ||
|
||
} // namespace osquery |
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.
nitpick, this comment looks like the result of a stray copy-paste
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.
Thanks! Updated.
I was testing with this branch to see if it would fix some unicode issues encountered and it fixed most of them! My current guess is that it has something to do with converting from unicode to UTF-8 before checking if the path exists in WindowsFindFile (fileops.cpp). I think we would also probably need to keep the path as a unicode string when checking the constraint/regex. |
Thanks for validating @sroache! I will take a look. It should call FindFirstFileW if it isn’t since FindFirstFileA is locale specific— I will check your case. |
I confirm what @sroache is seeing: I'd prefer to fix this issue in another PR after this is merged in vs adding more changes to this PR. |
The
*A
version of Windows API functions (e.g.,CreateFileA
,CreateEventA
, etc.) operate on system locale strings and not UTF-8 strings. Furthermore, projects generated with cmake use multi-byte character set. So, CreateFile is defined asCreateFileA
vsCreateFileW
. This causes weird display and input issues observable by the end-user and reported as bugs.In this PR, all these cases in the code (only osquery code and not externs) now call the
*W
versions of the Windows API functions, e.g.,CreateFileW
,CreateEventW
, respectively, and then narrow them to UTF-8 using osquery'swstringToString
.In some cases, we can safely call the
*A
functions, so these were kept as is (that is, osquery is choosing the input and this input is correct with the *A functions).Verified all test-cases passed locally.