From a0cd645e5b0e0f319df6ac208d09ce264c86ee93 Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Wed, 9 Oct 2024 17:09:59 -0700 Subject: [PATCH] Fix crash when handling jStayActiveMsec (#35997) --- src/controller/java/AndroidDeviceControllerWrapper.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index fccb1ba7cb05b6..ba0342629a73df 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -519,9 +519,15 @@ CHIP_ERROR AndroidDeviceControllerWrapper::ApplyICDRegistrationInfo(chip::Contro "()Ljava/lang/Long;", &getICDStayActiveDurationMsecMethod); ReturnErrorOnFailure(err); jobject jStayActiveMsec = env->CallObjectMethod(icdRegistrationInfo, getICDStayActiveDurationMsecMethod); - if (jStayActiveMsec != 0) + if (jStayActiveMsec != nullptr) { - params.SetICDStayActiveDurationMsec(chip::JniReferences::GetInstance().IntegerToPrimitive(jStayActiveMsec)); + jlong stayActiveMsec = chip::JniReferences::GetInstance().LongToPrimitive(jStayActiveMsec); + if (!chip::CanCastTo(stayActiveMsec)) + { + ChipLogError(Controller, "Failed to process stayActiveMsec in %s since this is not a valid 32-bit integer.", __func__); + return CHIP_ERROR_INVALID_ARGUMENT; + } + params.SetICDStayActiveDurationMsec(static_cast(stayActiveMsec)); } jmethodID getCheckInNodeIdMethod;