-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor exporter files: reduce noise and improve structure #54
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
Changes from all commits
3a6976e
019f8ca
96f912c
0477f5a
309b022
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,6 +60,15 @@ const char* CmdTypeToString(PschCmdType cmd) { | |||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Clamp a field length to its buffer maximum, warning on overflow. | ||||||||||||||||||||||||||||||||||||||||||||||
| template <typename LenT> | ||||||||||||||||||||||||||||||||||||||||||||||
| LenT ClampFieldLen(LenT len, LenT max, const char* field_name) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (len <= max) | ||||||||||||||||||||||||||||||||||||||||||||||
| return len; | ||||||||||||||||||||||||||||||||||||||||||||||
| elog(WARNING, "pg_stat_ch: invalid %s %u, clamping", field_name, static_cast<unsigned>(len)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+65
to
+68
|
||||||||||||||||||||||||||||||||||||||||||||||
| LenT ClampFieldLen(LenT len, LenT max, const char* field_name) { | |
| if (len <= max) | |
| return len; | |
| elog(WARNING, "pg_stat_ch: invalid %s %u, clamping", field_name, static_cast<unsigned>(len)); | |
| LenT ClampFieldLen(LenT len, LenT max, const char* field_name, const char* event_context = nullptr) { | |
| if (len <= max) | |
| return len; | |
| if (event_context != nullptr && event_context[0] != '\0') { | |
| elog(WARNING, | |
| "pg_stat_ch: invalid %s len=%llu max=%llu, clamping (%s)", | |
| field_name, | |
| static_cast<unsigned long long>(len), | |
| static_cast<unsigned long long>(max), | |
| event_context); | |
| } else { | |
| elog(WARNING, | |
| "pg_stat_ch: invalid %s len=%llu max=%llu, clamping", | |
| field_name, | |
| static_cast<unsigned long long>(len), | |
| static_cast<unsigned long long>(max)); | |
| } |
Copilot
AI
Apr 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datname_len and username_len are used directly to size std::string, but they are not validated against the fixed buffers (datname[64], username[64]). If an event ever contains an out-of-range length, this becomes an out-of-bounds read (and potentially data exfiltration/crash). Since you’re already clamping other variable-length fields, please clamp these too (e.g., to sizeof(ev.datname)-1 / sizeof(ev.username)-1) before constructing strings.
| col_db->Append(std::string(ev.datname, ev.datname_len)); | |
| col_username->Append(std::string(ev.username, ev.username_len)); | |
| auto dlen = | |
| ClampFieldLen(ev.datname_len, static_cast<uint8>(sizeof(ev.datname) - 1), "datname_len"); | |
| auto ulen = ClampFieldLen(ev.username_len, static_cast<uint8>(sizeof(ev.username) - 1), | |
| "username_len"); | |
| col_db->Append(std::string(ev.datname, dlen)); | |
| col_username->Append(std::string(ev.username, ulen)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InitLogPipeline() uses std::min but this file doesn’t include . It may compile today via transitive includes, but that’s not guaranteed; please add an explicit #include to make the dependency clear and robust.