Fix NULL pointer dereference in logcollector when no logfiles configured#2168
Merged
atomicturtle merged 2 commits intoossec:mainfrom Jan 23, 2026
Merged
Fix NULL pointer dereference in logcollector when no logfiles configured#2168atomicturtle merged 2 commits intoossec:mainfrom
atomicturtle merged 2 commits intoossec:mainfrom
Conversation
When all logfile tags are removed from ossec.conf, logcollector would segfault due to a NULL pointer dereference on line 292. The code was calling strncmp() on logff[i].logformat without checking if it was NULL. This fix adds a NULL check before the strncmp() call to prevent the segfault when no logfiles are configured. Fixes segfault reported on Ubuntu 22.04 (Jammy) with version 3.8.0.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a logcollector crash when no <localfile> entries are configured by preventing a NULL dereference during journald/command handling.
Changes:
- Add a NULL check before calling
strncmp()onlogff[i].logformatinside the main loop.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Based on code review feedback, the previous fix didn't handle the case where logformat is 'journald' but the binary is built without HAVE_SYSTEMD. In that case, logff[i].read is not set, and calling it later would crash. The improved fix checks if logff[i].read is set before attempting to call it, which handles both: - NULL logformat when no logfiles are configured - journald entries when built without HAVE_SYSTEMD support This is a more robust solution that prevents crashes in both scenarios.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When all logfile tags are removed from ossec.conf, logcollector would segfault due to a NULL pointer dereference on line 292. The code was calling strncmp() on logff[i].logformat without checking if it was NULL.
This fix adds a NULL check before the strncmp() call to prevent the segfault when no logfiles are configured.
Fixes segfault reported on Ubuntu 22.04 (Jammy) with version 3.8.0. Closes issue #2156