Skip to content

Commit

Permalink
Avoids buffer overflow in xmlrpcpp if fd > 1024
Browse files Browse the repository at this point in the history
A temporary fix to avoid buffer overflow in XmlRpcDispatch, since select() only works for file descriptors < FD_SETSIZE (1024). The real solution is to switch to poll as in #833, but since that PR was reverted, this avoids catastrophic failure. It throws instead of being silent, since (a) this behaviour is no less intrusive than a buffer overflow, and (b) returning an error was handled silently, and just looked like ros comm not being connected.
  • Loading branch information
kmactavish committed Aug 9, 2017
1 parent 4dd0a1a commit 9cad0e5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions utilities/xmlrpcpp/src/XmlRpcDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <math.h>
#include <errno.h>
#include <sys/timeb.h>
#include <stdexcept>
#if defined (__ANDROID__)
#include <sys/select.h>
#endif
Expand Down Expand Up @@ -95,6 +96,10 @@ XmlRpcDispatch::work(double timeout)
SourceList::iterator it;
for (it=_sources.begin(); it!=_sources.end(); ++it) {
int fd = it->getSource()->getfd();
if (fd >= FD_SETSIZE) {
_inWork = false;
throw std::runtime_error("XmlRpcDispatch::work: fd >= FD_SETSIZE limit, too many open files.");
}
if (it->getMask() & ReadableEvent) FD_SET(fd, &inFd);
if (it->getMask() & WritableEvent) FD_SET(fd, &outFd);
if (it->getMask() & Exception) FD_SET(fd, &excFd);
Expand Down

0 comments on commit 9cad0e5

Please sign in to comment.