summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2024-01-31 15:21:03 +0000
committerandrey-zelenkov <xim.andrew@gmail.com>2024-03-11 16:51:35 +0000
commit264b375506121d3a9268552b4f54c77faf171e6a (patch)
tree4a69653645c2ef29001a3524b5ae4362fe219628
parent7dcd6c0ebacab6d78ecc34cbac347ef46f79f479 (diff)
downloadunit-264b375506121d3a9268552b4f54c77faf171e6a.tar.gz
unit-264b375506121d3a9268552b4f54c77faf171e6a.tar.bz2
Avoiding arithmetic ops with NULL pointer in nxt_port_mmap_get
Can be reproduced by test/test_settings.py::test_settings_send_timeout with enabled UndefinedBehaviorSanitizer. Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r--src/nxt_port_memory.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c
index 0a4a6c53..be7688e2 100644
--- a/src/nxt_port_memory.c
+++ b/src/nxt_port_memory.c
@@ -454,6 +454,10 @@ nxt_port_mmap_get(nxt_task_t *task, nxt_port_mmaps_t *mmaps, nxt_chunk_id_t *c,
nxt_thread_mutex_lock(&mmaps->mutex);
+ if (nxt_slow_path(mmaps->elts == NULL)) {
+ goto end;
+ }
+
end_port_mmap = mmaps->elts + mmaps->size;
for (port_mmap = mmaps->elts;
@@ -500,6 +504,8 @@ nxt_port_mmap_get(nxt_task_t *task, nxt_port_mmaps_t *mmaps, nxt_chunk_id_t *c,
/* TODO introduce port_mmap limit and release wait. */
+end:
+
*c = 0;
mmap_handler = nxt_port_new_port_mmap(task, mmaps, tracking, n);