Skip to content

Comments

Fix NULL pointer dereference in logcollector when no logfiles configured#2168

Merged
atomicturtle merged 2 commits intoossec:mainfrom
atomicturtle:issue2156
Jan 23, 2026
Merged

Fix NULL pointer dereference in logcollector when no logfiles configured#2168
atomicturtle merged 2 commits intoossec:mainfrom
atomicturtle:issue2156

Conversation

@atomicturtle
Copy link
Member

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

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.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() on logff[i].logformat inside 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.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@atomicturtle atomicturtle merged commit 74fdf4a into ossec:main Jan 23, 2026
6 checks passed
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.

1 participant