Skip to content

Commit

Permalink
Lock SHM when using getstr() and addstr()
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Apr 14, 2019
1 parent 9c4c9d7 commit 3ab4076
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ static char *resolveHostname(const char *addr)
static size_t resolveAndAddHostname(size_t ippos, size_t oldnamepos)
{
// Get IP and host name strings
lock_shm();
const char* ipaddr = getstr(ippos);
const char* oldname = getstr(oldnamepos);
unlock_shm();

// Important: Don't hold a lock while resolving as the main thread
// (dnsmasq) needs to be operable during the call to resolveHostname()
Expand All @@ -79,7 +81,9 @@ static size_t resolveAndAddHostname(size_t ippos, size_t oldnamepos)
{
// We do not need to check for name == NULL as name is
// always initialized with an empty string at position 0
lock_shm();
size_t newnamepos = addstr(newname);
unlock_shm();
if(newname != NULL)
free(newname);
return newnamepos;
Expand Down

0 comments on commit 3ab4076

Please sign in to comment.