Repository navigation
Conversation
When building the lists of Unix-domain socket addresses from `unix_socket_directories` and `pcp_socket_dir`, `PgpoolMain()` skips an entry whose path is too long with a WARNING and `continue`. The address array is grown by `realloc()` to hold `num_unix_fds + 1` (`num_pcp_fds + 1`) elements, but the new element was written at the index of the loop counter `i`. Once an entry has been skipped, `i` is ahead of the number of stored entries, so the write lands one or more elements past the end of the array (heap buffer overflow), and the slots in front of it are left uninitialized. The uninitialized slot is later passed to `create_unix_domain_socket()` as a path to `unlink()` and `bind()`. Write the new address to the first free slot, `un_addrs[num_unix_fds]` (`pcp_un_addrs[num_pcp_fds]`), instead of `un_addrs[i]` (`pcp_un_addrs[i]`), so the array stays dense when entries are skipped, and matches the indexes used by its consumers. The problem is triggered only by a too-long directory followed by a valid one in `pgpool.conf`, so it needs a misconfiguration by an administrator and does not cross a privilege boundary.
Collaborator
|
Thank you for the report. I confirm the error and your patch fixes it. |
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.
When building the lists of Unix-domain socket addresses from
unix_socket_directoriesandpcp_socket_dir,PgpoolMain()skips an entry whose path is too long with a WARNING andcontinue. The address array is grown byrealloc()to holdnum_unix_fds + 1(num_pcp_fds + 1) elements, but the new element was written at the index of the loop counteri. Once an entry has been skipped,iis ahead of the number of stored entries, so the write lands one or more elements past the end of the array (heap buffer overflow), and the slots in front of it are left uninitialized. The uninitialized slot is later passed tocreate_unix_domain_socket()as a path tounlink()andbind().Write the new address to the first free slot,
un_addrs[num_unix_fds](pcp_un_addrs[num_pcp_fds]), instead ofun_addrs[i](pcp_un_addrs[i]), so the array stays dense when entries are skipped, and matches the indexes used by its consumers.The problem is triggered only by a too-long directory followed by a valid one in
pgpool.conf, so it needs a misconfiguration by an administrator and does not cross a privilege boundary.