sd-event: validate ssi_signo fits in signed int

Coverity flags si.ssi_signo as tainted data from read(), and warns
that casting it to signed could produce a negative value. Add an
explicit range check against INT_MAX before the SIGNAL_VALID check
to prove the cast is safe.

CID#1548033

Follow-up for c8b53fcfd3
This commit is contained in:
Luca Boccassi
2026-04-08 00:53:07 +01:00
parent 79a9a99728
commit fda487ef30

View File

@@ -3804,11 +3804,11 @@ static int process_signal(sd_event *e, struct signal_data *d, uint32_t events, i
if (_unlikely_(n != sizeof(si)))
return -EIO;
if (_unlikely_(!SIGNAL_VALID(si.ssi_signo)))
if (_unlikely_(si.ssi_signo > INT_MAX)) /* Ensure value fits in int before casting */
return -EIO;
/* Silence static analyzers */
assert(si.ssi_signo < _NSIG);
if (_unlikely_(!SIGNAL_VALID(si.ssi_signo)))
return -EIO;
if (e->signal_sources)
s = e->signal_sources[si.ssi_signo];