Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0] Fix process aborts when using cryptographic primitives with empty input for Android #77283

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace System.Security.Cryptography.Encryption.RC2.Tests
{
[SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
[ConditionalClass(typeof(RC2Factory), nameof(RC2Factory.IsSupported))]
public class RC2CipherOneShotTests : SymmetricOneShotBase
{
protected override byte[] Key => new byte[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ static jobject GetMessageDigestInstance(JNIEnv* env, intptr_t type)

int32_t CryptoNative_EvpDigestOneShot(intptr_t type, void* source, int32_t sourceSize, uint8_t* md, uint32_t* mdSize)
{
abort_if_invalid_pointer_argument (source);

if (!type || !md || !mdSize || sourceSize < 0)
if (!type || !md || !mdSize || sourceSize < 0 || (sourceSize > 0 && !source))
return FAIL;

JNIEnv* env = GetJNIEnv();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ int32_t CryptoNative_HmacReset(jobject ctx)

int32_t CryptoNative_HmacUpdate(jobject ctx, uint8_t* data, int32_t len)
{
if (!ctx)
// Callers are expected to skip update calls with no data.
if (!ctx || !data || len <= 0)
return FAIL;

abort_if_invalid_pointer_argument (data);
JNIEnv* env = GetJNIEnv();
jbyteArray dataBytes = make_java_byte_array(env, len);
(*env)->SetByteArrayRegion(env, dataBytes, 0, len, (jbyte*)data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ PALEXPORT void AndroidCryptoNative_RsaDestroy(RSA* rsa)

PALEXPORT int32_t AndroidCryptoNative_RsaPublicEncrypt(int32_t flen, uint8_t* from, uint8_t* to, RSA* rsa, RsaPadding padding)
{
abort_if_invalid_pointer_argument (from);
abort_if_invalid_pointer_argument (to);
abort_if_invalid_pointer_argument (rsa);

if ((flen > 0 && !from) || flen < 0)
return RSA_FAIL;

JNIEnv* env = GetJNIEnv();

int32_t ret = RSA_FAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public EvpHashProvider(IntPtr algorithmEvp)

public override void AppendHashData(ReadOnlySpan<byte> data)
{
if (data.IsEmpty)
{
return;
}

_running = true;
Check(Interop.Crypto.EvpDigestUpdate(_ctx, data, data.Length));
}
Expand Down Expand Up @@ -166,6 +171,11 @@ public HmacHashProvider(IntPtr algorithmEvp, ReadOnlySpan<byte> key)

public override void AppendHashData(ReadOnlySpan<byte> data)
{
if (data.IsEmpty)
{
return;
}

_running = true;
Check(Interop.Crypto.HmacUpdate(_hmacCtx, data, data.Length));
}
Expand Down