Skip to content

[#714] Guard NULL inputs in prefix/suffix helpers - #715

Open
hardikkaurani wants to merge 1 commit into
pgexporter:mainfrom
hardikkaurani:fix/utils-null-prefix-suffix
Open

hardikkaurani wants to merge 1 commit into
pgexporter:mainfrom
hardikkaurani:fix/utils-null-prefix-suffix

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Closes #714

Summary

  • Fix NULL pointer dereferences in pgexporter_remove_prefix() (src/libpgexporter/utils.c), which previously called strlen(orig) and strlen(prefix) before checking orig == NULL and prefix == NULL. Also check the malloc() return value before writing to the allocated buffer and use size_t for length arithmetic.
  • Guard NULL arguments in pgexporter_starts_with() and pgexporter_ends_with() (which also protects pgexporter_remove_suffix() when suffix == NULL).
  • Add NULL-input assertions to test_utils_starts_with and test_utils_ends_with, plus test_utils_remove_prefix_and_suffix in test/testcases/test_utils.c.

Verification

  • Formatted src/libpgexporter/utils.c and test/testcases/test_utils.c with clang-format (clang-format --dry-run --Werror passed).
  • Full build and MCTF + ASan suite will run in GitHub Actions CI.

Copilot AI balanced review requested due to automatic review settings November 29, 2026 21:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi @jesperpedersen and @ecleon26,

I opened this PR for #714 to fix NULL pointer dereferences in pgexporter_remove_prefix() and related prefix/suffix helpers (src/libpgexporter/utils.c):

  • Moved the orig == NULL and prefix == NULL checks before strlen(orig) and strlen(prefix) in pgexporter_remove_prefix(), added a NULL check on the malloc() result, and switched length arithmetic to size_t.
  • Added NULL guards to pgexporter_starts_with() and pgexporter_ends_with(), which also protects pgexporter_remove_suffix() when suffix == NULL.
  • Added NULL-input assertions to test_utils_starts_with and test_utils_ends_with, plus test_utils_remove_prefix_and_suffix in test/testcases/test_utils.c.

Formatted with clang-format and rebased onto main as a single commit (8977b55). Please let me know if any adjustments are needed.

@Pranav-error

Copy link
Copy Markdown
Collaborator

#692 is merged now. It fixes the Debug crash in test_connection_bind_unix_socket_permissions (#691), which is what fails both build-linux Debug jobs here. Please rebase on main.

@hardikkaurani
hardikkaurani force-pushed the fix/utils-null-prefix-suffix branch from 8977b55 to 928aba6 Compare December 2, 2026 21:32
@hardikkaurani

Copy link
Copy Markdown
Contributor Author

@Pranav-error Rebased onto main (928aba6) to pick up #692.

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.

Null pointer dereference in pgexporter_remove_prefix and prefix/suffix helpers

3 participants