Skip to content

chore: change memset to memset_s/SecureZeroMemory #105

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

Merged

Conversation

faviansamatha
Copy link
Contributor

memset can be declared as "unsafe" because compiler optimizations could remove it from the program. This is especially problematic when we rely on it to clear out data containing sensitive information such as password.

This PR changes the calls against for memset to pg_memset and it does this differently depending on UNIX and Windows.

UNIX: Change memset to use memset_s. memset_s is guaranteed to not be optimized away by the compiler.

Windows: Windows cannot use memset_s because it is an optional function in C11 and MSVC does not provide an implementation for it. In order to mitigate this, we can use SecureZeroMemory instead.

@davecramer davecramer merged commit e6bcc38 into postgresql-interfaces:main Apr 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants