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

Aberta
#230 0 comentários 0 reações 1 responsável Ver no GitHub

@MarioHewardt já está trabalhando nisso.

Desde 4/4/2026.

Avaliação

Esta issue ainda não foi avaliada.

Descrição

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)
Linguagem predominante
C
Estrelas
2.2k
Forks
224
Merge médio
4h 50min
PRs com merge (30d)
3

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de microsoft/Sysmon-Linux

Todas as issues de microsoft/Sysmon-Linux

Issues semelhantes

Mais issues de C

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.