Skip to content

Commit

Permalink
[#25846] YSQL: Fix segmentation fault generated around list iteration…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Devansh Saxena committed Feb 6, 2025
1 parent 65389e8 commit 43315ff
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/odyssey/sources/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 43315ff

Please sign in to comment.