fix: prevent NULL pointer crash in program_output on popen failure #3722
+14
−2
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.
Fix: Prevent NULL pointer crash in program_output on popen failure
Problem
The
output_programclass has a critical bug that causes Falco to crash with SIGSEGV (exit code 139) whenpopen()fails. This results in complete Falco shutdown and loss of all security monitoring.Root Causes
m_pfileis not initialized tonullptr, causing undefined behavior on first accesspopen()fails and returns NULL, bothsetvbuf()andfprintf()are called with a NULL pointerTrigger Scenarios
program_outputconfigurationpopen()failureImpact
program_outputfeatureSolution
Changes Made
File:
userspace/falco/outputs_program.hm_pfile = nullptrto ensure defined behaviorFile:
userspace/falco/outputs_program.cpplogger.h,<cerrno>,<cstring>popen()with error logging usingfalco_loggerfprintf()errnodetails in error message for debuggingCode Review
Before:
After:
Design Decisions
output_http(seeuserspace/falco/outputs_http.cpp:48-51)ERRlevel consistent with other output failureserrnofor debuggingTesting
Manual Testing Plan
Test invalid program path:
Test permission denied:
Test valid program:
Test keep_alive modes:
keep_alive: true- Program started once, reusedkeep_alive: false- Program restarted per alertAutomated Testing
Regression tests needed:
popen()failure handlingBuild Verification
Checklist
Related Issues
Additional Notes
This is a defensive fix that prevents a crash scenario that can occur in production. While the
program_outputfeature may not be widely used, when it is configured with an invalid path, the current code causes complete Falco failure rather than graceful degradation.The fix ensures Falco's core monitoring continues even when ancillary output mechanisms fail.