-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: crash on macOS/FreeBSD when running PostgreSQL queries #5360
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
base: v3.0
Are you sure you want to change the base?
Conversation
Fix NULL pointer dereference in CopyCmdMatcher that caused ProxySQL to crash immediately when running any PostgreSQL query on macOS and FreeBSD systems. Root cause: copy_cmd_matcher was guarded by #ifdef IDLE_THREADS, but IDLE_THREADS is explicitly disabled on macOS (__APPLE__) and FreeBSD in proxy_defines.h. This caused the pointer to be NULL when accessed. The fix removes #ifdef IDLE_THREADS guards from copy_cmd_matcher since COPY command detection is a fundamental PostgreSQL feature for fast- forward mode and has no dependency on idle threads. Affected systems: macOS, FreeBSD (where IDLE_THREADS is disabled) Fixes: #5359
Summary of ChangesHello @renecannao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a significant stability issue where PostgreSQL queries would cause a crash on macOS and FreeBSD. The problem stemmed from an incorrect conditional compilation directive that prevented the proper initialization of a key component, Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthroughThe pull request removes Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Code Review
This pull request addresses a crash on macOS and FreeBSD systems when executing PostgreSQL queries. The root cause was a NULL pointer dereference related to copy_cmd_matcher, which was incorrectly defined within an #ifdef IDLE_THREADS block that is disabled on these platforms. The fix involves moving the copy_cmd_matcher declaration and its lifecycle management (initialization, assignment, and cleanup) outside of the conditional compilation block. The changes are correct, well-reasoned, and effectively resolve the bug. The code is clean and the fix is well-contained.
|



Summary
Fixes a crash that occurred immediately when running any PostgreSQL query on macOS and FreeBSD systems.
Problem
ProxySQL crashed with a NULL pointer dereference in
CopyCmdMatcher::match()when processing PostgreSQL queries on macOS and FreeBSD.Backtrace:
Root Cause
copy_cmd_matcherwas guarded by#ifdef IDLE_THREADS, butIDLE_THREADSis explicitly disabled on macOS (__APPLE__) and FreeBSD inproxy_defines.h:5-8:This created an inconsistent configuration where:
PgSQL_Thread::copy_cmd_matcherwas not defined on macOS/FreeBSDPgSQL_Session::copy_cmd_matcherwas always definedPgSQL_Session.cpp:2924was not guarded → NULL pointer dereferenceSolution
Removed
#ifdef IDLE_THREADSguards fromcopy_cmd_matchersince:COPY ... FROM STDIN/STDOUTcommands for fast-forward modeChanges
include/PgSQL_Thread.h- MovedCopyCmdMatcher *copy_cmd_matcher;outside#ifdef IDLE_THREADSlib/PgSQL_Thread.cpp- Removed#ifdef IDLE_THREADSguards from initialization/cleanuplib/Base_Thread.cpp- Removed#ifdef IDLE_THREADSguard from copy operationTesting
Tested manually on macOS - PostgreSQL queries now work correctly without crashes.
Affected Systems
__APPLE__)__FreeBSD__)Fixes #5359
Summary by CodeRabbit