Skip to content

Commit

Permalink
Merge pull request #2121 from pi-hole/fix/binsearch_shm
Browse files Browse the repository at this point in the history
Fix fork shared memory access
  • Loading branch information
DL6ER authored Nov 18, 2024
2 parents 988a3c3 + 81d06bf commit f130216
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ static void remap_shm(void)
realloc_shm(&shm_strings, counters->strings_MAX, sizeof(char), false);
// strings are not exposed by a global pointer

realloc_shm(&shm_domains_lookup, counters->domains_lookup_MAX, sizeof(struct lookup_table), false);
domains_lookup = (struct lookup_table*)shm_domains_lookup.ptr;

realloc_shm(&shm_clients_lookup, counters->clients_lookup_MAX, sizeof(struct lookup_table), false);
clients_lookup = (struct lookup_table*)shm_clients_lookup.ptr;

realloc_shm(&shm_dns_cache_lookup, counters->dns_cache_lookup_MAX, sizeof(struct lookup_table), false);
dns_cache_lookup = (struct lookup_table*)shm_dns_cache_lookup.ptr;

// Update local counter to reflect that we absorbed this change
local_shm_counter = shmSettings->global_shm_counter;
}
Expand Down Expand Up @@ -1010,7 +1019,7 @@ void shm_ensure_size(void)
exit(EXIT_FAILURE);
}
}
if(counters->clients >= counters->clients_lookup_MAX-1)
if(counters->clients_lookup_size >= counters->clients_lookup_MAX-1)
{
// Have to reallocate shared memory
clients_lookup = enlarge_shmem_struct(CLIENTS_LOOKUP);
Expand All @@ -1020,7 +1029,7 @@ void shm_ensure_size(void)
exit(EXIT_FAILURE);
}
}
if(counters->domains >= counters->domains_lookup_MAX-1)
if(counters->domains_lookup_size >= counters->domains_lookup_MAX-1)
{
// Have to reallocate shared memory
domains_lookup = enlarge_shmem_struct(DOMAINS_LOOKUP);
Expand All @@ -1030,7 +1039,7 @@ void shm_ensure_size(void)
exit(EXIT_FAILURE);
}
}
if(counters->dns_cache_size >= counters->dns_cache_lookup_MAX-1)
if(counters->dns_cache_lookup_size >= counters->dns_cache_lookup_MAX-1)
{
// Have to reallocate shared memory
dns_cache_lookup = enlarge_shmem_struct(DNS_CACHE_LOOKUP);
Expand Down
2 changes: 1 addition & 1 deletion src/shmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static bool create_shm(const char *name, SharedMemory *sharedMemory, const size_
/// \param sharedMemory the shared memory struct
/// \param size1 the new size (factor 1)
/// \param size2 the new size (factor 2)
/// \param resize whether the object should be resized or only remapped
/// \param resize whether the object should be resized (true) or only remapped (false)
/// \return if reallocation was successful
static bool realloc_shm(SharedMemory *sharedMemory, const size_t size1, const size_t size2, const bool resize);

Expand Down

0 comments on commit f130216

Please sign in to comment.