From 5179915fb48c4a7415d7effe8eb88568ed033f40 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Sat, 10 Nov 2018 22:57:29 -0500 Subject: [PATCH] filesys/ncch: prevent buffer overflow on calculating SHA256 --- src/core/file_sys/ncch_container.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/file_sys/ncch_container.cpp b/src/core/file_sys/ncch_container.cpp index 4e9b2efa7..d913c8624 100644 --- a/src/core/file_sys/ncch_container.cpp +++ b/src/core/file_sys/ncch_container.cpp @@ -179,7 +179,9 @@ Loader::ResultStatus NCCHContainer::Load() { std::memcpy(input.data(), key_y_primary.data(), key_y_primary.size()); std::memcpy(input.data() + key_y_primary.size(), seed.data(), seed.size()); CryptoPP::SHA256 sha; - sha.CalculateDigest(key_y_secondary.data(), input.data(), input.size()); + std::array hash; + sha.CalculateDigest(hash.data(), input.data(), input.size()); + std::memcpy(key_y_secondary.data(), hash.data(), key_y_secondary.size()); } }