microsoft / microsoft/SysmonForLinux

fix: prevent division by zero in intHandler when no events received

Offen
#230 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@MarioHewardt arbeitet bereits daran.

Seit 04.4.2026.

Vorherrschende Sprache
C
Sterne
2.2k
Forks
220
Ø Merge
11 T. 22 Std.
Gemergte PRs (30 T.)
2

Beschreibung

Summary

Fix a potential division by zero crash in the intHandler signal
handler when Sysmon is stopped before processing any events
(totalEvents == 0).

Problem

In intHandler(), the following line:

printf("Total events: %ld, bad events: %ld, ratio = %f\n", 
    totalEvents, badEvents, (double)badEvents / totalEvents);

...will produce a division by zero (resulting in NaN or crash) if
Sysmon is interrupted immediately after startup before any eBPF
events are received.

Fix

Guard the division with a ternary check:

(double)badEvents / totalEvents
→
totalEvents > 0 ? (double)badEvents / totalEvents : 0.0

Testing

  • Start Sysmon and immediately send SIGINT (Ctrl+C)
  • Confirm clean output showing ratio = 0.000000 instead of crash/NaN

Notes

  • No functional change to normal operation
  • Zero risk of regression
  • Fixes undefined behavior per C standard (integer division by zero)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.