Skip to content

[#716] Require GET space prefix in pgexporter_http_server_parse - #717

Open
hardikkaurani wants to merge 1 commit into
pgexporter:mainfrom
hardikkaurani:fix/http-server-get-prefix-bounds
Open

hardikkaurani wants to merge 1 commit into
pgexporter:mainfrom
hardikkaurani:fix/http-server-get-prefix-bounds

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Closes #716

Summary

  • Fix pgexporter_http_server_parse() (src/libpgexporter/http_server.c) to require msg->length >= 4 and a "GET " 4-byte prefix instead of "GET" (3 bytes), preventing out-of-bounds pointer formation (msg->data + 4) on 3-byte "GET" payloads and rejecting non-GET methods starting with "GET" (e.g., "GETX/metrics").
  • Guard req == NULL and config == NULL before dereferencing them in pgexporter_http_server_parse().
  • Add test_http_server_parse_get_prefix in test/testcases/test_http.c covering 3-byte "GET", "GETX/metrics", and valid "GET /metrics" requests over a socket pair.

Verification

  • Formatted src/libpgexporter/http_server.c and test/testcases/test_http.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 22:04

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 #716 to tighten method validation and bounds checking in pgexporter_http_server_parse() (src/libpgexporter/http_server.c):

  • Updated the check from msg->length < 3 / "GET" to msg->length < 4 / "GET " so index = 4 stays within bounds on short payloads and non-GET methods starting with "GET" (such as "GETX/metrics") are rejected instead of having their fourth byte skipped.
  • Added NULL guards for req and config.
  • Added the test_http_server_parse_get_prefix regression test in test/testcases/test_http.c using socketpair().

Formatted with clang-format and rebased onto main as a single commit (2265f18). 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/http-server-get-prefix-bounds branch from 2265f18 to 731b379 Compare December 2, 2026 21:30
@hardikkaurani

Copy link
Copy Markdown
Contributor Author

@Pranav-error Rebased onto main (731b379) 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.

pgexporter_http_server_parse accepts non-GET prefix and forms OOB pointer on 3-byte GET

3 participants