diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-06 20:25:39 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-06 20:25:39 +0100 |
| commit | 97e58519bc946daabcadc531510497c3598961a1 (patch) | |
| tree | 74ecfb22d5666db86a1406b27313ffdf6f348879 /src | |
| parent | a282b339504380bd2b1d705720ea2de757ae5541 (diff) | |
Fix an accesslist reload issue where an empty-but-present changeset after a reload could potentially walk a NULL array
Diffstat (limited to 'src')
| -rw-r--r-- | src/ot_accesslist.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/ot_accesslist.c b/src/ot_accesslist.c index 0597e9a..487597e 100644 --- a/src/ot_accesslist.c +++ b/src/ot_accesslist.c | |||
| @@ -353,11 +353,17 @@ static void *accesslist_adddel_worker(const char *fifoname, ot_accesslist *_ | |||
| 353 | /* Only if the info hash is not in the adding_to list, create a new head with that entry */ | 353 | /* Only if the info hash is not in the adding_to list, create a new head with that entry */ |
| 354 | if (!exactmatch) { | 354 | if (!exactmatch) { |
| 355 | ot_accesslist *accesslist_new = accesslist_make(*adding_to, (*adding_to)->size + 1); | 355 | ot_accesslist *accesslist_new = accesslist_make(*adding_to, (*adding_to)->size + 1); |
| 356 | ptrdiff_t off = insert_point - (*adding_to)->list; | ||
| 357 | if (accesslist_new) { | 356 | if (accesslist_new) { |
| 358 | memcpy(accesslist_new->list, (*adding_to)->list, sizeof(ot_hash) * off); | 357 | ptrdiff_t off = (*adding_to)->size ? insert_point - (*adding_to)->list : 0; |
| 358 | size_t after = (*adding_to)->size - off; | ||
| 359 | |||
| 360 | /* A reload leaves an empty list with no array at all, and memcpy | ||
| 361 | may not be handed a null pointer even for nothing */ | ||
| 362 | if (off) | ||
| 363 | memcpy(accesslist_new->list, (*adding_to)->list, sizeof(ot_hash) * off); | ||
| 359 | memcpy(accesslist_new->list + off, info_hash, sizeof(info_hash)); | 364 | memcpy(accesslist_new->list + off, info_hash, sizeof(info_hash)); |
| 360 | memcpy(accesslist_new->list + off + 1, (*adding_to)->list + off, sizeof(ot_hash) * ((*adding_to)->size - off)); | 365 | if (after) |
| 366 | memcpy(accesslist_new->list + off + 1, (*adding_to)->list + off, sizeof(ot_hash) * after); | ||
| 361 | (*adding_to)->base = time_now_minutes(); | 367 | (*adding_to)->base = time_now_minutes(); |
| 362 | *adding_to = accesslist_new; | 368 | *adding_to = accesslist_new; |
| 363 | } | 369 | } |
