-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Let argument check run before aborting check. #61795
Conversation
Move abort check after the invalid arg check.
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsMove abort check after the invalid arg check. Fixes #61783
|
/azp help |
Supported commands
See additional documentation. |
/azp list |
I'm a bit confused how this is the cause of the linked issue. The failure was in What am I missing? |
@vcsjones Right. There are two issues actually in the same general area. The statement is for one and if one looks at the log it is for the other. Both are the same issue and I'm not sure why at this point, but the issue is around non-NULL for pointers even if the length is 0. The Android code path is much more aggressive about NULL as opposed to the other Linux approaches. I am looking into the other as well but wanted to try to run the Android leg to confirm with just this one. |
Might want to do a search for all instances of |
/azp run runtime-manual |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-manual |
Azure Pipelines successfully started running 1 pipeline(s). |
I'm actually not entirely sure how this worked before. The hash one-shot pins Lines 60 to 65 in 899bf97
and feeds that in to
So it goes to reason if you hash an empty span, runtime/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_evp.c Lines 51 to 55 in 57bfe47
|
@vcsjones That is exactly what I've been struggling with. I don't see how any of the generated changes caused this issue. I might just handle the /cc @elinor-fung |
I don't know what changed recently to undercover this. Perhaps something kicked in when we consolidated everything to That assert doesn't make much sense now that I look at it. Here's a patch I came up with to correct these two asserts: diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_evp.c b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_evp.c
index 3156d524503..04ff98209b0 100644
--- a/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_evp.c
+++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_evp.c
@@ -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();
diff --git a/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_hmac.c b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_hmac.c
index 7632eed5905..70f3030713a 100644
--- a/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_hmac.c
+++ b/src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_hmac.c
@@ -82,10 +82,12 @@ int32_t CryptoNative_HmacReset(jobject ctx)
int32_t CryptoNative_HmacUpdate(jobject ctx, uint8_t* data, int32_t len)
{
- if (!ctx)
+ if (!ctx || (len > 0 && !data))
return FAIL;
- abort_if_invalid_pointer_argument (data);
+ if (len == 0)
+ return SUCCESS;
+
JNIEnv* env = GetJNIEnv();
jbyteArray dataBytes = make_java_byte_array(env, len);
(*env)->SetByteArrayRegion(env, dataBytes, 0, len, (jbyte*)data); Explanations: An empty source makes sense for the hash one-shot iif the length is zero. Fully asserting it is not null doesn't make sense, it can be null if the length is zero. For the HmacUpdate, we can just return |
Personally, I'd just put an if in the managed code to avoid calling the P/Invoke if the length is zero. Saves on all the pinning and calling work. |
I can do that, too. @AaronRobinsonMSFT would you prefer I open a PR to replace this one? Happy to take it off your hands. |
@vcsjones I will take you up on that offer. Thanks. |
Move abort check after the invalid arg check.
Fixes #61783