Fix fortify_fatal issue during DNSServiceProcessResult()
fd was checked at beginnig of DNSServiceProcessResult()
but fd was changed to -1. So, fortify_fatal was occured
when FD_SET() was called.
Abort message: 'FORTIFY: FD_SET: file descriptor -1 < 0'
Test: Build
Bug: 120910016
Change-Id: Ib4c8dcc08223578fb53647637b44a20a4c221050
Signed-off-by: Sehee Park <sehee32.park@samsung.com>
diff --git a/server/MDnsSdListener.cpp b/server/MDnsSdListener.cpp
index 3903605..3133404 100644
--- a/server/MDnsSdListener.cpp
+++ b/server/MDnsSdListener.cpp
@@ -146,7 +146,7 @@
return;
}
if (VDBG) ALOGD("Stopping %s with ref %p", str, ref);
- DNSServiceRefDeallocate(*ref);
+ mMonitor->deallocateServiceRef(ref);
mMonitor->freeServiceRef(requestId);
char *msg;
asprintf(&msg, "%s stopped", str);
@@ -610,7 +610,9 @@
ALOGD("Monitor found [%d].revents = %d - calling ProcessResults",
i, mPollFds[i].revents);
}
+ pthread_mutex_lock(&mHeadMutex);
DNSServiceProcessResult(*(mPollRefs[i]));
+ pthread_mutex_unlock(&mHeadMutex);
mPollFds[i].revents = 0;
}
}
@@ -763,3 +765,9 @@
}
pthread_mutex_unlock(&mHeadMutex);
}
+
+void MDnsSdListener::Monitor::deallocateServiceRef(DNSServiceRef* ref) {
+ pthread_mutex_lock(&mHeadMutex);
+ DNSServiceRefDeallocate(*ref);
+ pthread_mutex_unlock(&mHeadMutex);
+}
\ No newline at end of file
diff --git a/server/MDnsSdListener.h b/server/MDnsSdListener.h
index bdf5d0c..1d613f9 100644
--- a/server/MDnsSdListener.h
+++ b/server/MDnsSdListener.h
@@ -79,8 +79,9 @@
int startService();
int stopService();
void run();
+ void deallocateServiceRef(DNSServiceRef* ref);
- private:
+ private:
int rescan(); // returns the number of elements in the poll
class Element {
public: