From 8a9e078e5427e2b72e178740f25cbcebb780b225 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Tue, 14 Mar 2023 17:31:48 +0000 Subject: Prevent a possible NULL de-reference in nxt_job_create(). We allocate 'job' we then have a check if it's not NULL and do stuff with it, but then we accessed it outside this check. Simply return if job is NULL. Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- src/nxt_job.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/nxt_job.c b/src/nxt_job.c index 995fd89b..56073953 100644 --- a/src/nxt_job.c +++ b/src/nxt_job.c @@ -32,12 +32,14 @@ nxt_job_create(nxt_mp_t *mp, size_t size) cache_size = size; } - if (nxt_fast_path(job != NULL)) { - job->cache_size = (uint16_t) cache_size; - job->mem_pool = mp; - nxt_job_set_name(job, "job"); + if (nxt_slow_path(job == NULL)) { + return NULL; } + job->cache_size = (uint16_t) cache_size; + job->mem_pool = mp; + nxt_job_set_name(job, "job"); + /* Allow safe nxt_queue_remove() in nxt_job_destroy(). */ nxt_queue_self(&job->link); -- cgit