зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1752332: Crash if a pref is accessed that shouldn't be r=KrisWright
Depends on D141417 Differential Revision: https://phabricator.services.mozilla.com/D141418
This commit is contained in:
Родитель
0d296a2db4
Коммит
fc925aadf4
|
@ -517,6 +517,13 @@ class Pref {
|
|||
MOZ_ASSERT(aKind == PrefValueKind::Default ? HasDefaultValue()
|
||||
: HasUserValue());
|
||||
|
||||
if (!XRE_IsParentProcess() &&
|
||||
ShouldSanitizePreference(Name(), XRE_IsContentProcess())) {
|
||||
MOZ_CRASH_UNSAFE_PRINTF(
|
||||
"Should not access the preference '%s' in the Content Processes",
|
||||
Name());
|
||||
}
|
||||
|
||||
return aKind == PrefValueKind::Default ? mDefaultValue.mBoolVal
|
||||
: mUserValue.mBoolVal;
|
||||
}
|
||||
|
@ -526,6 +533,13 @@ class Pref {
|
|||
MOZ_ASSERT(aKind == PrefValueKind::Default ? HasDefaultValue()
|
||||
: HasUserValue());
|
||||
|
||||
if (!XRE_IsParentProcess() &&
|
||||
ShouldSanitizePreference(Name(), XRE_IsContentProcess())) {
|
||||
MOZ_CRASH_UNSAFE_PRINTF(
|
||||
"Should not access the preference '%s' in the Content Processes",
|
||||
Name());
|
||||
}
|
||||
|
||||
return aKind == PrefValueKind::Default ? mDefaultValue.mIntVal
|
||||
: mUserValue.mIntVal;
|
||||
}
|
||||
|
@ -536,6 +550,13 @@ class Pref {
|
|||
MOZ_ASSERT(aKind == PrefValueKind::Default ? HasDefaultValue()
|
||||
: HasUserValue());
|
||||
|
||||
if (!XRE_IsParentProcess() &&
|
||||
ShouldSanitizePreference(Name(), XRE_IsContentProcess())) {
|
||||
MOZ_CRASH_UNSAFE_PRINTF(
|
||||
"Should not access the preference '%s' in the Content Processes",
|
||||
Name());
|
||||
}
|
||||
|
||||
return aKind == PrefValueKind::Default ? mDefaultValue.mStringVal
|
||||
: mUserValue.mStringVal;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,12 @@ class SharedPrefMapBuilder;
|
|||
|
||||
typedef const char* String;
|
||||
|
||||
template <typename T>
|
||||
struct IsString : std::false_type {};
|
||||
|
||||
template <>
|
||||
struct IsString<String> : std::true_type {};
|
||||
|
||||
typedef Atomic<bool, Relaxed> RelaxedAtomicBool;
|
||||
typedef Atomic<bool, ReleaseAcquire> ReleaseAcquireAtomicBool;
|
||||
typedef Atomic<bool, SequentiallyConsistent> SequentiallyConsistentAtomicBool;
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
// namespace.
|
||||
|
||||
#include "StaticPrefsBase.h"
|
||||
#include "Preferences.h"
|
||||
#include "MainThreadUtils.h" // for NS_IsMainThread()
|
||||
#include "nsXULAppAPI.h" // for XRE_IsContentProcess()
|
||||
|
||||
namespace mozilla {
|
||||
namespace StaticPrefs {
|
||||
|
@ -17,23 +19,33 @@ namespace StaticPrefs {
|
|||
// For mirrored prefs we generate an extern variable declaration and three
|
||||
// getter declarations/definitions.
|
||||
#define NEVER_PREF(name, cpp_type, default_value)
|
||||
#define ALWAYS_PREF(name, base_id, full_id, cpp_type, default_value) \
|
||||
extern cpp_type sMirror_##full_id; \
|
||||
inline StripAtomic<cpp_type> full_id() { \
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsAtomic<cpp_type>::value || NS_IsMainThread(), \
|
||||
"Non-atomic static pref '" name \
|
||||
"' being accessed on background thread by getter"); \
|
||||
return sMirror_##full_id; \
|
||||
} \
|
||||
inline const char* GetPrefName_##base_id() { return name; } \
|
||||
inline StripAtomic<cpp_type> GetPrefDefault_##base_id() { \
|
||||
return default_value; \
|
||||
#define ALWAYS_PREF(name, base_id, full_id, cpp_type, default_value) \
|
||||
extern cpp_type sMirror_##full_id; \
|
||||
inline StripAtomic<cpp_type> full_id() { \
|
||||
if (!XRE_IsParentProcess() && IsString<cpp_type>::value) { \
|
||||
MOZ_DIAGNOSTIC_ASSERT( \
|
||||
!ShouldSanitizePreference(name, XRE_IsContentProcess()), \
|
||||
"Should not access the preference '" name "' in Content Processes"); \
|
||||
} \
|
||||
MOZ_DIAGNOSTIC_ASSERT(IsAtomic<cpp_type>::value || NS_IsMainThread(), \
|
||||
"Non-atomic static pref '" name \
|
||||
"' being accessed on background thread by getter"); \
|
||||
return sMirror_##full_id; \
|
||||
} \
|
||||
inline const char* GetPrefName_##base_id() { return name; } \
|
||||
inline StripAtomic<cpp_type> GetPrefDefault_##base_id() { \
|
||||
return default_value; \
|
||||
}
|
||||
#define ONCE_PREF(name, base_id, full_id, cpp_type, default_value) \
|
||||
extern cpp_type sMirror_##full_id; \
|
||||
inline cpp_type full_id() { \
|
||||
MaybeInitOncePrefs(); \
|
||||
return sMirror_##full_id; \
|
||||
} \
|
||||
inline const char* GetPrefName_##base_id() { return name; } \
|
||||
#define ONCE_PREF(name, base_id, full_id, cpp_type, default_value) \
|
||||
extern cpp_type sMirror_##full_id; \
|
||||
inline cpp_type full_id() { \
|
||||
MaybeInitOncePrefs(); \
|
||||
if (!XRE_IsParentProcess() && IsString<cpp_type>::value) { \
|
||||
MOZ_DIAGNOSTIC_ASSERT( \
|
||||
!ShouldSanitizePreference(name, XRE_IsContentProcess()), \
|
||||
"Should not access the preference '" name "' in Content Processes"); \
|
||||
} \
|
||||
return sMirror_##full_id; \
|
||||
} \
|
||||
inline const char* GetPrefName_##base_id() { return name; } \
|
||||
inline cpp_type GetPrefDefault_##base_id() { return default_value; }
|
||||
|
|
Загрузка…
Ссылка в новой задаче