Skip to content

Commit

Permalink
Propagate ignoreInvalidMessageForTesting to the NetworkProcess
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264821
rdar://118404748

Reviewed by Alex Christensen.

This change propagates ignoreInvalidMessageForTesting to the
NetworkConnectionToWebProcess.

* Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::didReceiveSyncMessage):
* Source/WebKit/NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::createNetworkConnectionToWebProcess):
* Source/WebKit/Shared/NetworkProcessConnectionParameters.h:
* Source/WebKit/Shared/NetworkProcessConnectionParameters.serialization.in:
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::getNetworkProcessConnection):

Canonical link: https://commits.webkit.org/271305@main
  • Loading branch information
gavin-apple committed Nov 29, 2023
1 parent 5977b19 commit dd412bf
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

PASS Sending sync message to the UI process with incorrect parameters must throw error
PASS Sending sync message to the GPU process with incorrect parameters must throw error
PASS Sending sync message with incorrect parameters must throw error

Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@
if (!window.IPC)
return;

assert_throws_js(TypeError,
() => { IPC.sendSyncMessage("UI", 0, IPC.messages.IPCTester_SyncPingEmptyReply.name, defaultTimeout, []); },
`failed sync message must throw error`);
}, "Sending sync message to the UI process with incorrect parameters must throw error");

promise_test(async t => {
if (!window.IPC)
return;

assert_throws_js(TypeError,
() => { IPC.sendSyncMessage("GPU", 0, IPC.messages.IPCTester_SyncPingEmptyReply.name, defaultTimeout, []); },
`failed sync message must throw error`);
}, "Sending sync message to the GPU process with incorrect parameters must throw error");
for (const processTarget of IPC.processTargets) {
assert_throws_js(TypeError,
() => { IPC.sendSyncMessage(processTarget, 0, IPC.messages.IPCTester_SyncPingEmptyReply.name, defaultTimeout, []); },
`failed sync message must throw error`);
}
}, "Sending sync message with incorrect parameters must throw error");

</script>
</body>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

PASS Sending sync stream message with incorrect parameters to the UI process shouldn't crash when IPCTestingAPI is enabled
PASS Sending sync stream message with incorrect parameters to the GPU process shouldn't crash when IPCTestingAPI is enabled
PASS Sending sync stream message with incorrect parameters shouldn't crash when IPCTestingAPI is enabled

Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,27 @@
if (!window.IPC)
return;

const [streamConnection, serverConnectionHandle] = IPC.createStreamClientConnection(bufferSizeLog2);
streamConnection.open();
IPC.sendMessage("UI", 0, IPC.messages.IPCTester_CreateStreamTester.name, [
{ type: 'uint64_t', value: streamTesterID },
{ type: 'StreamServerConnectionHandle', value: serverConnectionHandle },
]);
const arguments = streamConnection.waitForMessage(streamTesterID, IPC.messages.IPCStreamTesterProxy_WasCreated.name, defaultTimeout);
streamConnection.setSemaphores(arguments[0].value, arguments[1].value);

// Test starts here.
try {
assert_throws_js(TypeError,
() => { streamConnection.sendSyncMessage(streamTesterID, IPC.messages.IPCStreamTester_SyncMessageEmptyReply.name, defaultTimeout, [ ]) },
`failed sync message must throw error`);
} finally {
IPC.sendSyncMessage("UI", 0, IPC.messages.IPCTester_ReleaseStreamTester.name, defaultTimeout, [{ type: 'uint64_t', value: streamTesterID }]);
streamConnection.invalidate();
}

}, "Sending sync stream message with incorrect parameters to the UI process shouldn't crash when IPCTestingAPI is enabled");

promise_test(async t => {
if (!window.IPC)
return;

const [streamConnection, serverConnectionHandle] = IPC.createStreamClientConnection(bufferSizeLog2);
streamConnection.open();
IPC.sendMessage("GPU", 0, IPC.messages.IPCTester_CreateStreamTester.name, [
{ type: 'uint64_t', value: streamTesterID },
{ type: 'StreamServerConnectionHandle', value: serverConnectionHandle },
]);
const arguments = streamConnection.waitForMessage(streamTesterID, IPC.messages.IPCStreamTesterProxy_WasCreated.name, defaultTimeout);
streamConnection.setSemaphores(arguments[0].value, arguments[1].value);

// Test starts here.
try {
assert_throws_js(TypeError,
() => { streamConnection.sendSyncMessage(streamTesterID, IPC.messages.IPCStreamTester_SyncMessageEmptyReply.name, defaultTimeout, [ ]) },
`failed sync message must throw error`);
} finally {
IPC.sendSyncMessage("GPU", 0, IPC.messages.IPCTester_ReleaseStreamTester.name, defaultTimeout, [{ type: 'uint64_t', value: streamTesterID }]);
streamConnection.invalidate();
for (const processTarget of IPC.processTargets) {
const [streamConnection, serverConnectionHandle] = IPC.createStreamClientConnection(bufferSizeLog2);
streamConnection.open();
IPC.sendMessage(processTarget, 0, IPC.messages.IPCTester_CreateStreamTester.name, [
{ type: 'uint64_t', value: streamTesterID },
{ type: 'StreamServerConnectionHandle', value: serverConnectionHandle },
]);
const arguments = streamConnection.waitForMessage(streamTesterID, IPC.messages.IPCStreamTesterProxy_WasCreated.name, defaultTimeout);
streamConnection.setSemaphores(arguments[0].value, arguments[1].value);

// Test starts here.
try {
assert_throws_js(TypeError,
() => { streamConnection.sendSyncMessage(streamTesterID, IPC.messages.IPCStreamTester_SyncMessageEmptyReply.name, defaultTimeout, [ ]) },
`failed sync message must throw error`);
} finally {
IPC.sendSyncMessage(processTarget, 0, IPC.messages.IPCTester_ReleaseStreamTester.name, defaultTimeout, [{ type: 'uint64_t', value: streamTesterID }]);
streamConnection.invalidate();
}
}

}, "Sending sync stream message with incorrect parameters to the GPU process shouldn't crash when IPCTestingAPI is enabled");
}, "Sending sync stream message with incorrect parameters shouldn't crash when IPCTestingAPI is enabled");

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,8 @@ bool NetworkConnectionToWebProcess::didReceiveSyncMessage(IPC::Connection& conne
#endif

#if ENABLE(IPC_TESTING_API)
if (decoder.messageReceiverName() == Messages::IPCTester::messageReceiverName()) {
m_ipcTester.didReceiveSyncMessage(connection, decoder, reply);
return true;
}
if (decoder.messageReceiverName() == Messages::IPCTester::messageReceiverName())
return m_ipcTester.didReceiveSyncMessage(connection, decoder, reply);
#endif

// Add new receiver name tests above this.
Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/NetworkProcess/NetworkProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ void NetworkProcess::createNetworkConnectionToWebProcess(ProcessIdentifier ident

connection->setOnLineState(NetworkStateNotifier::singleton().onLine());

#if ENABLE(IPC_TESTING_API)
if (parameters.ignoreInvalidMessageForTesting)
connection->connection().setIgnoreInvalidMessageForTesting();
#endif

if (auto* session = networkSession(sessionID))
session->storageManager().startReceivingMessageFromConnection(Ref { connection->connection() });
}
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/Shared/NetworkProcessConnectionParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace WebKit {

struct NetworkProcessConnectionParameters {
bool allowTestOnlyIPC { false };
#if ENABLE(IPC_TESTING_API)
bool ignoreInvalidMessageForTesting { false };
#endif
};

}; // namespace WebKit
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@

struct WebKit::NetworkProcessConnectionParameters {
bool allowTestOnlyIPC;
#if ENABLE(IPC_TESTING_API)
bool ignoreInvalidMessageForTesting;
#endif
};
7 changes: 6 additions & 1 deletion Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,12 @@ void NetworkProcessProxy::getNetworkProcessConnection(WebProcessProxy& webProces
{
RELEASE_LOG(ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because a web process is requesting a connection", this);
startResponsivenessTimer(UseLazyStop::No);
sendWithAsyncReply(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess { webProcessProxy.coreProcessIdentifier(), webProcessProxy.sessionID(), { webProcessProxy.allowTestOnlyIPC() } }, [this, weakThis = WeakPtr { *this }, reply = WTFMove(reply)](auto&& identifier, auto cookieAcceptPolicy) mutable {
NetworkProcessConnectionParameters parameters;
parameters.allowTestOnlyIPC = webProcessProxy.allowTestOnlyIPC();
#if ENABLE(IPC_TESTING_API)
parameters.ignoreInvalidMessageForTesting = webProcessProxy.ignoreInvalidMessageForTesting();
#endif
sendWithAsyncReply(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess { webProcessProxy.coreProcessIdentifier(), webProcessProxy.sessionID(), parameters }, [this, weakThis = WeakPtr { *this }, reply = WTFMove(reply)](auto&& identifier, auto cookieAcceptPolicy) mutable {
if (!weakThis) {
RELEASE_LOG_ERROR(Process, "NetworkProcessProxy::getNetworkProcessConnection: NetworkProcessProxy deallocated during connection establishment");
return reply({ });
Expand Down

0 comments on commit dd412bf

Please sign in to comment.