Bug 1042387 - Add file descriptors count check r=jrmuizel

This commit is contained in:
Sotaro Ikeda 2014-08-18 10:55:23 -07:00
parent 63f391665c
commit c0eceb28a8
4 changed files with 11 additions and 12 deletions

View File

@ -49,8 +49,6 @@ ParamTraits<FenceHandle>::Write(Message* aMsg,
flattenable->flatten(data, nbytes, fds, nfds);
#endif
aMsg->WriteSize(nbytes);
aMsg->WriteSize(nfds);
aMsg->WriteBytes(data, nbytes);
for (size_t n = 0; n < nfds; ++n) {
// These buffers can't die in transit because they're created
@ -65,15 +63,14 @@ ParamTraits<FenceHandle>::Read(const Message* aMsg,
void** aIter, paramType* aResult)
{
size_t nbytes;
size_t nfds;
const char* data;
if (!aMsg->ReadSize(aIter, &nbytes) ||
!aMsg->ReadSize(aIter, &nfds) ||
!aMsg->ReadBytes(aIter, &data, nbytes)) {
return false;
}
size_t nfds = aMsg->num_fds();
int fds[nfds];
for (size_t n = 0; n < nfds; ++n) {
@ -141,8 +138,6 @@ ParamTraits<FenceHandleFromChild>::Write(Message* aMsg,
flattenable->flatten(data, nbytes, fds, nfds);
#endif
aMsg->WriteSize(nbytes);
aMsg->WriteSize(nfds);
aMsg->WriteBytes(data, nbytes);
for (size_t n = 0; n < nfds; ++n) {
// If the Fence was shared cross-process, SCM_RIGHTS does
@ -166,15 +161,14 @@ ParamTraits<FenceHandleFromChild>::Read(const Message* aMsg,
void** aIter, paramType* aResult)
{
size_t nbytes;
size_t nfds;
const char* data;
if (!aMsg->ReadSize(aIter, &nbytes) ||
!aMsg->ReadSize(aIter, &nfds) ||
!aMsg->ReadBytes(aIter, &data, nbytes)) {
return false;
}
size_t nfds = aMsg->num_fds();
int fds[nfds];
for (size_t n = 0; n < nfds; ++n) {

View File

@ -97,8 +97,6 @@ ParamTraits<MagicGrallocBufferHandle>::Write(Message* aMsg,
aMsg->WriteInt(aParam.mRef.mOwner);
aMsg->WriteInt64(aParam.mRef.mKey);
aMsg->WriteSize(nbytes);
aMsg->WriteSize(nfds);
aMsg->WriteBytes(data, nbytes);
for (size_t n = 0; n < nfds; ++n) {
// These buffers can't die in transit because they're created
@ -113,7 +111,6 @@ ParamTraits<MagicGrallocBufferHandle>::Read(const Message* aMsg,
void** aIter, paramType* aResult)
{
size_t nbytes;
size_t nfds;
const char* data;
int owner;
int64_t index;
@ -121,12 +118,12 @@ ParamTraits<MagicGrallocBufferHandle>::Read(const Message* aMsg,
if (!aMsg->ReadInt(aIter, &owner) ||
!aMsg->ReadInt64(aIter, &index) ||
!aMsg->ReadSize(aIter, &nbytes) ||
!aMsg->ReadSize(aIter, &nfds) ||
!aMsg->ReadBytes(aIter, &data, nbytes)) {
printf_stderr("ParamTraits<MagicGrallocBufferHandle>::Read() failed to read a message\n");
return false;
}
size_t nfds = aMsg->num_fds();
int fds[nfds];
bool sameProcess = (XRE_GetProcessType() == GeckoProcessType_Default);
for (size_t n = 0; n < nfds; ++n) {

View File

@ -159,6 +159,10 @@ void Message::EnsureFileDescriptorSet() {
file_descriptor_set_ = new FileDescriptorSet;
}
uint32_t Message::num_fds() const {
return file_descriptor_set() ? file_descriptor_set()->size() : 0;
}
#endif
} // namespace IPC

View File

@ -204,6 +204,10 @@ class Message : public Pickle {
name_ = name;
}
#if defined(OS_POSIX)
uint32_t num_fds() const;
#endif
template<class T>
static bool Dispatch(const Message* msg, T* obj, void (T::*func)()) {
(obj->*func)();