From 43315ff2c09f4e0035a5fb0c14a60e5d9eb4f646 Mon Sep 17 00:00:00 2001 From: Devansh Saxena Date: Thu, 6 Feb 2025 09:31:06 +0530 Subject: [PATCH] [#25846] YSQL: Fix segmentation fault generated around list iteration in odyssey Summary: The macro for iterating over circular linked list in odyssey has an issue where code can access next iterator for a NULL pointer. This can cause segmentation fault and resulting in core-dump generated like this. ``` * thread #1, name = 'odyssey', stop reason = signal SIGSEGV: address not mapped to object * frame #0: 0x000055c867e54c24 odyssey`od_hashmap_free(hm=0x000004527f8e2f10) at hashmap.c:101:3 frame #1: 0x000055c867e46556 odyssey`od_client_free(client=0x000004527fd9a500) at client.h:180:3 frame #2: 0x000055c867e45f2a odyssey`od_frontend [inlined] od_frontend_close(client=0x000004527fd9a500) at frontend.c:35:2 frame #3: 0x000055c867e45ec9 odyssey`od_frontend(arg=0x000004527fd9a500) at frontend.c:2728:2 frame #4: 0x000055c867e69572 odyssey`mm_scheduler_main(arg=0x000004527fd693b0) at scheduler.c:17:2 frame #5: 0x000055c867e69a27 odyssey`mm_context_runner at context.c:28:2 ``` This diff fixes this bug. Jira: DB-15141 Test Plan: Jenkins: all tests, enable connection manager Reviewers: rbarigidad Reviewed By: rbarigidad Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D41646 --- src/odyssey/sources/list.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/odyssey/sources/list.h b/src/odyssey/sources/list.h index c74291e8067f..b3d60cf367e1 100644 --- a/src/odyssey/sources/list.h +++ b/src/odyssey/sources/list.h @@ -54,11 +54,11 @@ static inline int od_list_empty(od_list_t *list) } #define od_list_foreach(list, iterator) \ - for (iterator = (list)->next; iterator != list; \ + for (iterator = (list)->next; iterator && iterator != list; \ iterator = (iterator)->next) #define od_list_foreach_safe(list, iterator, safe) \ for (iterator = (list)->next; \ - iterator != list && (safe = iterator->next); iterator = safe) + iterator && iterator != list && (safe = iterator->next); iterator = safe) #endif /* ODYSSEY_LIST_H */