Skip to content

Commit

Permalink
Avoid Android crash during QRCode Parsing (#22655)
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo authored Sep 15, 2022
1 parent 822993c commit 7d707fa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/setup_payload/java/SetupPayloadParser-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,8 @@ jobject TransformSetupPayload(JNIEnv * env, SetupPayload & payload)
jclass enumClass = env->FindClass("chip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType");
jfieldID enumType = nullptr;

switch (info.tag)
switch (info.type)
{
case optionalQRCodeInfoTypeUnknown:
enumType =
env->GetStaticFieldID(enumClass, "TYPE_UNKNOWN", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;");
break;
case optionalQRCodeInfoTypeString:
enumType =
env->GetStaticFieldID(enumClass, "TYPE_STRING", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;");
Expand All @@ -184,12 +180,18 @@ jobject TransformSetupPayload(JNIEnv * env, SetupPayload & payload)
enumType =
env->GetStaticFieldID(enumClass, "TYPE_UINT64", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;");
break;
default:
case optionalQRCodeInfoTypeUnknown:
default: // Optional Type variable has to set any value.
enumType =
env->GetStaticFieldID(enumClass, "TYPE_UNKNOWN", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;");
break;
}

jobject enumObj = env->GetStaticObjectField(enumClass, enumType);
env->SetObjectField(optionalInfo, type, enumObj);
if (enumType != nullptr)
{
jobject enumObj = env->GetStaticObjectField(enumClass, enumType);
env->SetObjectField(optionalInfo, type, enumObj);
}

env->SetObjectField(optionalInfo, data, env->NewStringUTF(info.data.c_str()));
env->SetIntField(optionalInfo, int32, info.int32);
Expand Down

0 comments on commit 7d707fa

Please sign in to comment.