Skip to content
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

fix(maild): email messages are sent infinitely #1658

Merged
merged 1 commit into from
Jan 29, 2019

Conversation

knqyf263
Copy link
Contributor

@knqyf263 knqyf263 commented Jan 28, 2019

Hi there

First of all, I'd like to thank you for such a wonderful tool.

In my environment, email messages are sent infinitely when multiple alerts are detected in a short period of time.

The following is the mail related setting.

  <global>
    <email_notification>yes</email_notification>
    <email_to>[email protected]</email_to>
    <smtp_server>127.0.0.1</smtp_server>
    <email_from>ossecm@localhost</email_from>
    <logall>yes</logall>
    <email_maxperhour>9999</email_maxperhour>
  </global>

  <email_alerts>
    <email_to>[email protected]</email_to>
    <event_location>192.168.33.2</event_location>
    <do_not_delay />
    <do_not_group />
  </email_alerts>

  <alerts>
    <log_alert_level>1</log_alert_level>
    <email_alert_level>5</email_alert_level>
  </alerts>

After debugging, I noticed that the position of fp used in GetAlertData of read-alert.c sometimes went to the beginning of a file.

I further investigated and found that fp was changed when the forked child process exited after OS_Sendmail of maild.c.

Then, I found this issue. Looking at the answer, this is not a bug of libc.
https://sourceware.org/bugzilla/show_bug.cgi?id=23151

Here are some excerpts from the relevant section
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_05_01

If the stream is open with a mode that allows reading and the underlying open file description refers to a device that is capable of seeking, the application shall either perform an fflush(), or the stream shall be closed.

After adding fflush() before fork, this problem no longer reproduces.

Thanks.

@knqyf263 knqyf263 changed the title fix(maild): email are sent infinitely fix(maild): email messages are sent infinitely Jan 28, 2019
@ddpbsd ddpbsd merged commit 35ae0ab into ossec:master Jan 29, 2019
@knqyf263 knqyf263 deleted the fix/fflush_before_fork branch January 29, 2019 21:26
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.

2 participants