Skip to content

Commit 2099fa7

Browse files
committed
Address feedback
1 parent 122323c commit 2099fa7

File tree

2 files changed

+8
-5
lines changed
  • src
    • libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android
    • native/libs/System.Security.Cryptography.Native.Android

2 files changed

+8
-5
lines changed

src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Cipher.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ internal static unsafe bool EvpAeadCipherFinalEx(
150150
out int bytesWritten,
151151
out bool authTagMismatch)
152152
{
153-
// We can't pass null down to the native shim, so create a valid pointer if we have an empty span,
154-
// thus, we use MemoryMarshal.GetNonNullPinnableReference
155-
fixed (byte* pOutput = &MemoryMarshal.GetNonNullPinnableReference(output))
153+
fixed (byte* pOutput = output)
156154
{
157155
return EvpAeadCipherFinalEx(ctx, pOutput, out bytesWritten, out authTagMismatch);
158156
}

src/native/libs/System.Security.Cryptography.Native.Android/pal_cipher.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ int32_t AndroidCryptoNative_AeadCipherFinalEx(CipherCtx* ctx, uint8_t* outm, int
305305
if (!ctx)
306306
return FAIL;
307307

308-
abort_if_invalid_pointer_argument(outm);
308+
// outm is allowed to be NULL
309309
abort_if_invalid_pointer_argument(outl);
310310
abort_if_invalid_pointer_argument(authTagMismatch);
311311

@@ -335,7 +335,12 @@ int32_t AndroidCryptoNative_AeadCipherFinalEx(CipherCtx* ctx, uint8_t* outm, int
335335

336336
jsize outBytesLen = (*env)->GetArrayLength(env, outBytes);
337337
*outl = outBytesLen;
338-
(*env)->GetByteArrayRegion(env, outBytes, 0, outBytesLen, (jbyte*) outm);
338+
339+
if (outBytesLen > 0)
340+
{
341+
abort_if_invalid_pointer_argument(outm);
342+
(*env)->GetByteArrayRegion(env, outBytes, 0, outBytesLen, (jbyte*) outm);
343+
}
339344

340345
(*env)->DeleteLocalRef(env, outBytes);
341346
return CheckJNIExceptions(env) ? FAIL : SUCCESS;

0 commit comments

Comments
 (0)