]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
mutex lock the g_localaddresses as under very rare conditions it can segfault at...
authorMark Zealey <mark.zealey@itsolve.co.uk>
Wed, 4 Dec 2013 20:30:02 +0000 (20:30 +0000)
committerMark Zealey <mark.zealey@itsolve.co.uk>
Wed, 4 Dec 2013 20:30:41 +0000 (20:30 +0000)
pdns/nameserver.cc

index 0e773fa30029c610d935fadb5feb715284885cf7..990a7457c4b5a001e3b86ef62d73356b1881c4ba 100644 (file)
@@ -89,6 +89,7 @@ extern StatBag S;
 #endif
 
 vector<ComboAddress> g_localaddresses; // not static, our unit tests need to poke this
+pthread_mutex_t localaddresses_lock=PTHREAD_MUTEX_INITIALIZER;
 
 void UDPNameserver::bindIPv4()
 {
@@ -129,7 +130,10 @@ void UDPNameserver::bindIPv4()
     if(locala.sin4.sin_family != AF_INET) 
       throw PDNSException("Attempting to bind IPv4 socket to IPv6 address");
 
+    pthread_mutex_lock(&localaddresses_lock);
     g_localaddresses.push_back(locala);
+    pthread_mutex_unlock(&localaddresses_lock);
+
     if(::bind(s, (sockaddr*)&locala, locala.getSocklen()) < 0) {
       L<<Logger::Error<<"binding UDP socket to '"+locala.toStringWithPort()+": "<<strerror(errno)<<endl;
       throw PDNSException("Unable to bind to UDP socket");