bug 1097998 - Warn when using CPOWs when content process isn't in a safe state r=billm, bholley

This commit is contained in:
Brad Lassey 2015-01-02 13:50:21 -05:00
parent d1c0f96396
commit 033d1d7603
4 changed files with 28 additions and 0 deletions

View File

@ -1606,6 +1606,25 @@ ContentParent::OnChannelError()
PContentParent::OnChannelError();
}
void
ContentParent::OnBeginSyncTransaction() {
if (XRE_GetProcessType() == GeckoProcessType_Default) {
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
JSContext *cx = nsContentUtils::GetCurrentJSContext();
if (console && cx) {
nsAutoString filename;
uint32_t lineno = 0;
nsJSUtils::GetCallingLocation(cx, filename, &lineno);
nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
error->Init(NS_LITERAL_STRING("unsafe CPOW usage"), filename, EmptyString(),
lineno, 0, nsIScriptError::warningFlag, "chrome javascript");
console->LogMessage(error);
} else {
NS_WARNING("Unsafe synchronous IPC message");
}
}
}
void
ContentParent::OnChannelConnected(int32_t pid)
{

View File

@ -253,6 +253,8 @@ public:
virtual void OnChannelError() MOZ_OVERRIDE;
virtual void OnBeginSyncTransaction() MOZ_OVERRIDE;
virtual PCrashReporterParent*
AllocPCrashReporterParent(const NativeThreadId& tid,
const uint32_t& processType) MOZ_OVERRIDE;

View File

@ -719,6 +719,9 @@ MessageChannel::Send(Message* aMsg, Message* aReply)
AssertWorkerThread();
mMonitor->AssertNotCurrentThreadOwns();
if (mCurrentTransaction == 0)
mListener->OnBeginSyncTransaction();
#ifdef OS_WIN
SyncStackFrame frame(this, false);
#endif

View File

@ -88,6 +88,10 @@ class MessageListener
virtual void OnExitedCall() {
NS_RUNTIMEABORT("default impl shouldn't be invoked");
}
/* This callback is called when a sync message is sent that begins a new IPC transaction
(i.e., when it is not part of an existing sequence of nested messages). */
virtual void OnBeginSyncTransaction() {
}
virtual RacyInterruptPolicy MediateInterruptRace(const Message& parent,
const Message& child)
{