Repository navigation
Remove unsafe strpos() helper - #70
Merged
Merged
Conversation
strpos() was only used to print the position of the GLOBAL keyword in
two DEBUG1 messages, but it was unsafe:
* malloc(strlen(hay)) leaves no room for the terminating NUL, and the
following strncpy() copies exactly strlen(hay) - offset bytes, so
the buffer passed to strstr() is not NUL-terminated and strstr()
reads past the end of the allocation (heap buffer over-read,
confirmed with AddressSanitizer);
* the malloc'ed buffer was never freed, and neither was the palloc'ed
copy returned by asc_toupper(), so every logged CREATE GLOBAL
TEMPORARY TABLE leaked the size of the query string;
* on allocation failure it called exit() from inside a backend,
bypassing PostgreSQL's error handling.
The arguments of elog() are only evaluated when the message is going
to be emitted, so this code ran whenever DEBUG1 was enabled through
client_min_messages or log_min_messages.
The position of GLOBAL in the query string has no diagnostic value
(the statement is known to start with CREATE GLOBAL at this point), so
remove the helper and the extra argument from the two debug messages
instead of rewriting it. The utils/formatting.h include, only needed
for asc_toupper(), is removed as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
strpos() was only used to print the position of the GLOBAL keyword in two DEBUG1 messages, but it was unsafe:
The arguments of elog() are only evaluated when the message is going to be emitted, so this code ran whenever DEBUG1 was enabled through client_min_messages or log_min_messages.
The position of GLOBAL in the query string has no diagnostic value (the statement is known to start with CREATE GLOBAL at this point), so remove the helper and the extra argument from the two debug messages instead of rewriting it. The utils/formatting.h include, only needed for asc_toupper(), is removed as well.
(LLM identification and fix with human in the loop)