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

Downtime::AddDowntime(): NULL-check pointer before deref not to crash #10049

Merged
merged 4 commits into from
May 6, 2024

Conversation

Al2Klimov
Copy link
Member

@Al2Klimov Al2Klimov commented Apr 23, 2024

The method already checks whether triggeredBy is empty before GetByName(triggeredBy). But a non-empty string doesn't necessarily name an existing Downtime. I.e. the pointer from GetByName(triggeredBy) must be NULL-checked.

ref/IP/46868

(gdb) frame 7
#7  icinga::Downtime::AddDowntime (checkable=..., author=..., comment=...,
    startTime=1713696054, endTime=1713699654, fixed=<optimized out>,
    triggeredBy=..., duration=3600, scheduledDowntime=..., scheduledBy=...,
    parent=..., id=..., origin=...)
    at /usr/src/debug/icinga2-2.14.0-1.el8.x86_64/lib/icinga/downtime.cpp:331
331			Array::Ptr triggers = parentDowntime->GetTriggers();
(gdb) p parentDowntime
$1 = {px = 0x0}
(gdb)

CC @tbauriedel

Edit

Btw. complain on such bad input via API.

@Al2Klimov Al2Klimov added bug Something isn't working area/api REST API core/crash Shouldn't happen, requires attention ref/IP consider backporting Should be considered for inclusion in a bugfix release labels Apr 23, 2024
@cla-bot cla-bot bot added the cla/signed label Apr 23, 2024
@tbauriedel
Copy link
Member

ref/NC/789598

…heir names

to avoid names of vanished objects.
@Al2Klimov
Copy link
Member Author

> POST /v1/actions/schedule-downtime HTTP/1.1
> Host: 127.0.0.1:5665
> Authorization: Basic cm9vdDoxMjM0NTY=
> User-Agent: curl/8.4.0
> Accept: application/json
> Content-Length: 147
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 404 Not Found
< Server: Icinga/v2.14.0-158-g5ba652af9
< Content-Type: application/json
< Content-Length: 937
<
* Connection #0 to host 127.0.0.1 left intact
{"results":[{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."},{"code":404,"status":"Won't schedule downtime with non-existent trigger downtime."}]}

👍

lib/icinga/apiactions.cpp Outdated Show resolved Hide resolved
lib/icinga/downtime.cpp Show resolved Hide resolved
lib/icinga/downtime.cpp Show resolved Hide resolved
For this purpose lookup the specified Downtime. Also pass Downtime objects,
not just names, to Downtime::AddDowntime() not to lookup it twice.
@Al2Klimov Al2Klimov added this to the 2.15.0 milestone Apr 25, 2024
@Al2Klimov Al2Klimov merged commit 8c2eb3c into master May 6, 2024
26 checks passed
@Al2Klimov Al2Klimov deleted the AddDowntime-trigger_name branch May 6, 2024 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api REST API bug Something isn't working cla/signed consider backporting Should be considered for inclusion in a bugfix release core/crash Shouldn't happen, requires attention ref/IP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants