From 434c56fcd27119d902aa71201283f9537697ed91 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Fri, 17 Jul 2015 21:36:13 -0400 Subject: Cleared UBsan error using non-null pointer --- pssr.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'pssr.cpp') diff --git a/pssr.cpp b/pssr.cpp index 2220a9b6..f76f994a 100644 --- a/pssr.cpp +++ b/pssr.cpp @@ -75,8 +75,17 @@ void PSSR_MEM_Base::ComputeMessageRepresentative(RandomNumberGenerator &rng, xorStart[0] ^= 1; xorbuf(xorStart + 1, recoverableMessage, recoverableMessageLength); xorbuf(xorStart + 1 + recoverableMessageLength, salt, salt.size()); - memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second); - representative[representativeByteLength - 1] = hashIdentifier.second ? 0xcc : 0xbc; + + if(representative && hashIdentifier.first && hashIdentifier.second) + { + memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second); + representative[representativeByteLength - 1] = 0xcc; + } + else + { + representative[representativeByteLength - 1] = 0xbc; + } + if (representativeBitLength % 8 != 0) representative[0] = (byte)Crop(representative[0], representativeBitLength % 8); } @@ -116,7 +125,8 @@ DecodingResult PSSR_MEM_Base::RecoverMessageFromRepresentative( && (size_t)(M - representative - (representativeBitLength % 8 != 0)) >= MinPadLen(digestSize) && recoverableMessageLength <= MaxRecoverableLength(representativeBitLength, hashIdentifier.second, digestSize)) { - memcpy(recoverableMessage, M+1, recoverableMessageLength); + if(recoverableMessage && M && recoverableMessageLength) + memcpy(recoverableMessage, M+1, recoverableMessageLength); } else { -- cgit v1.2.1