Skip to content

Commit da2183c

Browse files
committedFeb 11, 2022
Bug 1754305 - Make assertions in Maybe MOZ_RELEASE_ASSERT, r=glandium a=RyanVM
These assertions are already diagnostic asserts, and this will make failures to check Maybe into safe crashes rather than security bugs on all branches. A failure to check Maybe is more dangerous than a null pointer dereference, as the generated code will produce a valid reference to uninitialized data rather than a null reference which should safely segfault. Differential Revision: https://phabricator.services.mozilla.com/D138208
1 parent 2758d1e commit da2183c

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed
 

‎mfbt/Maybe.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ class MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS Maybe
455455
* avoid multiple calls. Unsafe unless |isSome()|.
456456
*/
457457
T extract() {
458-
MOZ_DIAGNOSTIC_ASSERT(isSome());
458+
MOZ_RELEASE_ASSERT(isSome());
459459
T v = std::move(mStorage.val);
460460
reset();
461461
return v;
@@ -683,7 +683,7 @@ class Maybe<T&> {
683683
constexpr bool isNothing() const { return !mValue; }
684684

685685
T& ref() const {
686-
MOZ_DIAGNOSTIC_ASSERT(isSome());
686+
MOZ_RELEASE_ASSERT(isSome());
687687
return *mValue;
688688
}
689689

@@ -743,98 +743,98 @@ class Maybe<T&> {
743743

744744
template <typename T>
745745
constexpr T Maybe<T>::value() const& {
746-
MOZ_DIAGNOSTIC_ASSERT(isSome());
746+
MOZ_RELEASE_ASSERT(isSome());
747747
return ref();
748748
}
749749

750750
template <typename T>
751751
constexpr T Maybe<T>::value() && {
752-
MOZ_DIAGNOSTIC_ASSERT(isSome());
752+
MOZ_RELEASE_ASSERT(isSome());
753753
return std::move(ref());
754754
}
755755

756756
template <typename T>
757757
constexpr T Maybe<T>::value() const&& {
758-
MOZ_DIAGNOSTIC_ASSERT(isSome());
758+
MOZ_RELEASE_ASSERT(isSome());
759759
return std::move(ref());
760760
}
761761

762762
template <typename T>
763763
T* Maybe<T>::ptr() {
764-
MOZ_DIAGNOSTIC_ASSERT(isSome());
764+
MOZ_RELEASE_ASSERT(isSome());
765765
return &ref();
766766
}
767767

768768
template <typename T>
769769
constexpr const T* Maybe<T>::ptr() const {
770-
MOZ_DIAGNOSTIC_ASSERT(isSome());
770+
MOZ_RELEASE_ASSERT(isSome());
771771
return &ref();
772772
}
773773

774774
template <typename T>
775775
constexpr T* Maybe<T>::operator->() {
776-
MOZ_DIAGNOSTIC_ASSERT(isSome());
776+
MOZ_RELEASE_ASSERT(isSome());
777777
return ptr();
778778
}
779779

780780
template <typename T>
781781
constexpr const T* Maybe<T>::operator->() const {
782-
MOZ_DIAGNOSTIC_ASSERT(isSome());
782+
MOZ_RELEASE_ASSERT(isSome());
783783
return ptr();
784784
}
785785

786786
template <typename T>
787787
constexpr T& Maybe<T>::ref() & {
788-
MOZ_DIAGNOSTIC_ASSERT(isSome());
788+
MOZ_RELEASE_ASSERT(isSome());
789789
return mStorage.val;
790790
}
791791

792792
template <typename T>
793793
constexpr const T& Maybe<T>::ref() const& {
794-
MOZ_DIAGNOSTIC_ASSERT(isSome());
794+
MOZ_RELEASE_ASSERT(isSome());
795795
return mStorage.val;
796796
}
797797

798798
template <typename T>
799799
constexpr T&& Maybe<T>::ref() && {
800-
MOZ_DIAGNOSTIC_ASSERT(isSome());
800+
MOZ_RELEASE_ASSERT(isSome());
801801
return std::move(mStorage.val);
802802
}
803803

804804
template <typename T>
805805
constexpr const T&& Maybe<T>::ref() const&& {
806-
MOZ_DIAGNOSTIC_ASSERT(isSome());
806+
MOZ_RELEASE_ASSERT(isSome());
807807
return std::move(mStorage.val);
808808
}
809809

810810
template <typename T>
811811
constexpr T& Maybe<T>::operator*() & {
812-
MOZ_DIAGNOSTIC_ASSERT(isSome());
812+
MOZ_RELEASE_ASSERT(isSome());
813813
return ref();
814814
}
815815

816816
template <typename T>
817817
constexpr const T& Maybe<T>::operator*() const& {
818-
MOZ_DIAGNOSTIC_ASSERT(isSome());
818+
MOZ_RELEASE_ASSERT(isSome());
819819
return ref();
820820
}
821821

822822
template <typename T>
823823
constexpr T&& Maybe<T>::operator*() && {
824-
MOZ_DIAGNOSTIC_ASSERT(isSome());
824+
MOZ_RELEASE_ASSERT(isSome());
825825
return std::move(ref());
826826
}
827827

828828
template <typename T>
829829
constexpr const T&& Maybe<T>::operator*() const&& {
830-
MOZ_DIAGNOSTIC_ASSERT(isSome());
830+
MOZ_RELEASE_ASSERT(isSome());
831831
return std::move(ref());
832832
}
833833

834834
template <typename T>
835835
template <typename... Args>
836836
constexpr void Maybe<T>::emplace(Args&&... aArgs) {
837-
MOZ_DIAGNOSTIC_ASSERT(!isSome());
837+
MOZ_RELEASE_ASSERT(!isSome());
838838
::new (KnownNotNull, &mStorage.val) T(std::forward<Args>(aArgs)...);
839839
mIsSome = true;
840840
}

0 commit comments

Comments
 (0)