Skip to content

Commit 52bc9d0

Browse files
committed
ensure usages can fit in a uint8_t
1 parent 11e4095 commit 52bc9d0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

c-dependencies/js-compute-runtime/builtins/crypto-key.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "crypto-algorithm.h"
33
#include "js-compute-builtins.h"
44
#include "openssl/rsa.h"
5+
#include <utility>
56

67
namespace builtins {
78

@@ -315,8 +316,9 @@ bool CryptoKey::usages_get(JSContext *cx, unsigned argc, JS::Value *vp) {
315316
}
316317
// Else, grab the CryptoKeyUsages value from Slots::Usages and convert
317318
// it into a JS Array and store the result in Slots::UsagesArray.
318-
auto usage =
319-
CryptoKeyUsages(static_cast<uint8_t>(JS::GetReservedSlot(self, Slots::Usages).toInt32()));
319+
auto usages = JS::GetReservedSlot(self, Slots::Usages).toInt32();
320+
MOZ_ASSERT(std::in_range<std::uint8_t>(usages));
321+
auto usage = CryptoKeyUsages(static_cast<uint8_t>(usages));
320322
// The result is ordered alphabetically.
321323
JS::RootedValueVector result(cx);
322324
JS::RootedString str(cx);
@@ -641,8 +643,10 @@ JS::Result<bool> CryptoKey::is_algorithm(JSContext *cx, JS::HandleObject self,
641643

642644
bool CryptoKey::canSign(JS::HandleObject self) {
643645
MOZ_ASSERT(is_instance(self));
644-
auto usage = CryptoKeyUsages(JS::GetReservedSlot(self, Slots::Usages).toInt32());
646+
auto usages = JS::GetReservedSlot(self, Slots::Usages).toInt32();
647+
MOZ_ASSERT(std::in_range<std::uint8_t>(usages));
648+
auto usage = CryptoKeyUsages(static_cast<uint8_t>(usages));
645649
return usage.canSign();
646650
}
647651

648-
} // namespace builtins
652+
} // namespace builtins

0 commit comments

Comments
 (0)