Bug 1752332: Remove the shouldSanitizeFunction member r=KrisWright

In the following patch we are going to change the signature of
ShouldSanitizePreference to take a Pref object.  Pref is only
known to the Preferences compilation unit; so to keep this member
(whose signature will change) we would need to expose the Pref
class. However it will only be a forward declaration, one could
not construct a Pref object in e.g. the gtest.

It is simpler to just remove the member entirely and call
ShouldSanitizePreference unconditionally - the member was only
used for the gtest, and while the gtest will be less robust
because of this change, it will still do some testing.

Depends on D141419

Differential Revision: https://phabricator.services.mozilla.com/D141420
This commit is contained in:
Tom Ritter 2022-04-21 13:22:51 +00:00
parent 1b7e20d742
commit 735f58c46f
12 changed files with 26 additions and 42 deletions

View File

@ -2532,8 +2532,7 @@ bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
// Instantiate the pref serializer. It will be cleaned up in // Instantiate the pref serializer. It will be cleaned up in
// `LaunchSubprocessReject`/`LaunchSubprocessResolve`. // `LaunchSubprocessReject`/`LaunchSubprocessResolve`.
mPrefSerializer = MakeUnique<mozilla::ipc::SharedPreferenceSerializer>( mPrefSerializer = MakeUnique<mozilla::ipc::SharedPreferenceSerializer>();
ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_Content, if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_Content,
GetRemoteType())) { GetRemoteType())) {
NS_WARNING("SharedPreferenceSerializer::SerializeToSharedMemory failed"); NS_WARNING("SharedPreferenceSerializer::SerializeToSharedMemory failed");

View File

@ -46,8 +46,7 @@ bool RDDProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched); MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched);
MOZ_ASSERT(!mRDDChild); MOZ_ASSERT(!mRDDChild);
mPrefSerializer = mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_RDD, if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_RDD,
/* remoteType */ ""_ns)) { /* remoteType */ ""_ns)) {
return false; return false;

View File

@ -42,8 +42,7 @@ bool GPUProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(!mGPUChild); MOZ_ASSERT(!mGPUChild);
MOZ_ASSERT(!gfxPlatform::IsHeadless()); MOZ_ASSERT(!gfxPlatform::IsHeadless());
mPrefSerializer = mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_GPU, if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_GPU,
/* remoteType */ ""_ns)) { /* remoteType */ ""_ns)) {
return false; return false;

View File

@ -55,8 +55,7 @@ bool VRProcessParent::Launch() {
std::vector<std::string> extraArgs; std::vector<std::string> extraArgs;
ProcessChild::AddPlatformBuildID(extraArgs); ProcessChild::AddPlatformBuildID(extraArgs);
mPrefSerializer = mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_VR, if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_VR,
/* remoteType */ ""_ns)) { /* remoteType */ ""_ns)) {
return false; return false;

View File

@ -27,8 +27,7 @@ void SetThisProcessName(const char* aName);
class SharedPreferenceSerializer final { class SharedPreferenceSerializer final {
public: public:
explicit SharedPreferenceSerializer( explicit SharedPreferenceSerializer();
std::function<bool(const char*, bool)>&& aShouldSanitizeFn);
SharedPreferenceSerializer(SharedPreferenceSerializer&& aOther); SharedPreferenceSerializer(SharedPreferenceSerializer&& aOther);
~SharedPreferenceSerializer(); ~SharedPreferenceSerializer();
@ -51,7 +50,6 @@ class SharedPreferenceSerializer final {
size_t mPrefsLength; size_t mPrefsLength;
UniqueFileHandle mPrefMapHandle; UniqueFileHandle mPrefMapHandle;
UniqueFileHandle mPrefsHandle; UniqueFileHandle mPrefsHandle;
std::function<bool(const char*, bool)> mShouldSanitizeFn;
}; };
class SharedPreferenceDeserializer final { class SharedPreferenceDeserializer final {

View File

@ -18,9 +18,8 @@
namespace mozilla { namespace mozilla {
namespace ipc { namespace ipc {
SharedPreferenceSerializer::SharedPreferenceSerializer( SharedPreferenceSerializer::SharedPreferenceSerializer()
std::function<bool(const char*, bool)>&& aShouldSanitizeFn) : mPrefMapSize(0), mPrefsLength(0) {
: mPrefMapSize(0), mPrefsLength(0), mShouldSanitizeFn(aShouldSanitizeFn) {
MOZ_COUNT_CTOR(SharedPreferenceSerializer); MOZ_COUNT_CTOR(SharedPreferenceSerializer);
} }
@ -50,7 +49,7 @@ bool SharedPreferenceSerializer::SerializeToSharedMemory(
// Serialize the early prefs. // Serialize the early prefs.
nsAutoCStringN<1024> prefs; nsAutoCStringN<1024> prefs;
Preferences::SerializePreferences(prefs, mShouldSanitizeFn, destIsWebContent); Preferences::SerializePreferences(prefs, destIsWebContent);
mPrefsLength = prefs.Length(); mPrefsLength = prefs.Length();
base::SharedMemory shm; base::SharedMemory shm;

View File

@ -60,8 +60,7 @@ bool UtilityProcessHost::Launch(StringVector aExtraOpts) {
MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched); MOZ_ASSERT(mLaunchPhase == LaunchPhase::Unlaunched);
MOZ_ASSERT(!mUtilityProcessParent); MOZ_ASSERT(!mUtilityProcessParent);
mPrefSerializer = mPrefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_Utility, if (!mPrefSerializer->SerializeToSharedMemory(GeckoProcessType_Utility,
/* remoteType */ ""_ns)) { /* remoteType */ ""_ns)) {
return false; return false;

View File

@ -49,8 +49,7 @@ already_AddRefed<IPDLUnitTestParent> IPDLUnitTestParent::CreateCrossProcess() {
std::vector<std::string> extraArgs; std::vector<std::string> extraArgs;
auto prefSerializer = auto prefSerializer = MakeUnique<ipc::SharedPreferenceSerializer>();
MakeUnique<ipc::SharedPreferenceSerializer>(ShouldSanitizePreference);
if (!prefSerializer->SerializeToSharedMemory(GeckoProcessType_IPDLUnitTest, if (!prefSerializer->SerializeToSharedMemory(GeckoProcessType_IPDLUnitTest,
/* remoteType */ ""_ns)) { /* remoteType */ ""_ns)) {
ADD_FAILURE() ADD_FAILURE()

View File

@ -3611,10 +3611,8 @@ NS_IMPL_ISUPPORTS(Preferences, nsIPrefService, nsIObserver, nsIPrefBranch,
nsISupportsWeakReference) nsISupportsWeakReference)
/* static */ /* static */
void Preferences::SerializePreferences( void Preferences::SerializePreferences(nsCString& aStr,
nsCString& aStr, bool aIsDestinationWebContentProcess) {
const std::function<bool(const char*, bool)>& aShouldSanitizeFn,
bool aIsDestinationContentProcess) {
MOZ_RELEASE_ASSERT(InitStaticMembers()); MOZ_RELEASE_ASSERT(InitStaticMembers());
aStr.Truncate(); aStr.Truncate();
@ -3623,7 +3621,8 @@ void Preferences::SerializePreferences(
Pref* pref = iter.get().get(); Pref* pref = iter.get().get();
if (!pref->IsTypeNone() && pref->HasAdvisablySizedValues()) { if (!pref->IsTypeNone() && pref->HasAdvisablySizedValues()) {
pref->SerializeAndAppend( pref->SerializeAndAppend(
aStr, aShouldSanitizeFn(pref->Name(), aIsDestinationContentProcess)); aStr,
ShouldSanitizePreference(pref, aIsDestinationWebContentProcess));
} }
} }

View File

@ -400,10 +400,8 @@ class Preferences final : public nsIPrefService,
// When a content process is created these methods are used to pass changed // When a content process is created these methods are used to pass changed
// prefs in bulk from the parent process, via shared memory. // prefs in bulk from the parent process, via shared memory.
static void SerializePreferences( static void SerializePreferences(nsCString& aStr,
nsCString& aStr, bool aIsDestinationWebContentProcess);
const std::function<bool(const char*, bool)>& aShouldSanitizeFn,
bool aIsDestinationContentProcess);
static void DeserializePreferences(char* aStr, size_t aPrefsLen); static void DeserializePreferences(char* aStr, size_t aPrefsLen);
static mozilla::ipc::FileDescriptor EnsureSnapshot(size_t* aSize); static mozilla::ipc::FileDescriptor EnsureSnapshot(size_t* aSize);

View File

@ -43,17 +43,13 @@ TEST(PrefsBasics, Serialize)
true); true);
nsCString str; nsCString str;
Preferences::SerializePreferences( Preferences::SerializePreferences(str, true);
str, [](const char* aPref, bool) -> bool { return true; }, true); fprintf(stderr, "%s\n", str.Data());
// Assert everything was marked sanitized // Assert that some prefs were not sanitized
ASSERT_EQ(nullptr, strstr(str.Data(), "--:")); ASSERT_NE(nullptr, strstr(str.Data(), "B--:"));
ASSERT_NE(nullptr, strstr(str.Data(), "I--:"));
Preferences::SerializePreferences( ASSERT_NE(nullptr, strstr(str.Data(), "S--:"));
str, // Assert that something was sanitized
[](const char* aPref, bool) -> bool { ASSERT_NE(nullptr,
return strncmp(aPref, "foo.bool", 8) == 0; strstr(str.Data(), "I-S:56/datareporting.policy.dataSubmissionPolicyAcceptedVersion"));
},
true);
// Assert the sanitized serializtion was found
ASSERT_NE(nullptr, strstr(str.Data(), "B-S:8/foo.bool:T:\n"));
} }

View File

@ -68,7 +68,7 @@ bool SocketProcessHost::Launch() {
std::vector<std::string> extraArgs; std::vector<std::string> extraArgs;
ProcessChild::AddPlatformBuildID(extraArgs); ProcessChild::AddPlatformBuildID(extraArgs);
SharedPreferenceSerializer prefSerializer(ShouldSanitizePreference); SharedPreferenceSerializer prefSerializer;
if (!prefSerializer.SerializeToSharedMemory(GeckoProcessType_VR, if (!prefSerializer.SerializeToSharedMemory(GeckoProcessType_VR,
/* remoteType */ ""_ns)) { /* remoteType */ ""_ns)) {
return false; return false;