-
Notifications
You must be signed in to change notification settings - Fork 60
Fix JNI string lifetime/null-safety, Windows cancel-drain race, and UWP version parse #1494
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
base: main
Are you sure you want to change the base?
Changes from all commits
cd2f1a9
4c176db
dca30a7
778a2e5
772ce61
80f865c
25df775
1274680
76d75ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,19 @@ Java_com_microsoft_applications_events_Signals_sendSignal(JNIEnv *env, | |
| jlong nativeLoggerPtr, | ||
| jstring signal_item_json) { | ||
| jboolean isCopy = true; | ||
| if (signal_item_json == nullptr) { | ||
| return false; | ||
| } | ||
| const char *signalItemJson = (env)->GetStringUTFChars(signal_item_json, &isCopy); | ||
| env->ReleaseStringUTFChars(signal_item_json, signalItemJson); | ||
| if (signalItemJson == nullptr) { | ||
| // GetStringUTFChars returned null (e.g. OOM, with a pending exception); | ||
| // there is nothing valid to log. | ||
| return false; | ||
| } | ||
|
Comment on lines
+28
to
+36
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This early-return is intentional and is the fix, not a regression. |
||
|
|
||
| auto logger = reinterpret_cast<ILogger*>(nativeLoggerPtr); | ||
| EventProperties eventProperties = Signals::CreateEventProperties(signalItemJson); | ||
|
bmehta001 marked this conversation as resolved.
|
||
| env->ReleaseStringUTFChars(signal_item_json, signalItemJson); | ||
| logger->LogEvent(eventProperties); | ||
| return true; | ||
| } | ||
|
|
@@ -54,11 +62,18 @@ Java_com_microsoft_applications_events_Signals_nativeInitialize(JNIEnv *env, jcl | |
| SubstrateSignalsConfiguration config; | ||
|
|
||
| jboolean isCopy = true; | ||
| const char *convertedValue = (env)->GetStringUTFChars(base_url, &isCopy); | ||
| if (strlen(convertedValue) > 0) { | ||
| config.ServiceRequestConfig.BaseUrl = convertedValue; | ||
| if (base_url != nullptr) { | ||
| const char *convertedValue = (env)->GetStringUTFChars(base_url, &isCopy); | ||
| if (convertedValue == nullptr) { | ||
| // GetStringUTFChars failed (e.g. OOM) and left a pending exception; | ||
| // do not continue making JNI calls with an exception in flight. | ||
| return false; | ||
| } | ||
| if (strlen(convertedValue) > 0) { | ||
| config.ServiceRequestConfig.BaseUrl = convertedValue; | ||
| } | ||
| env->ReleaseStringUTFChars(base_url, convertedValue); | ||
|
Comment on lines
64
to
+75
|
||
| } | ||
| env->ReleaseStringUTFChars(base_url, convertedValue); | ||
|
|
||
| config.ServiceRequestConfig.TimeoutMs = reinterpret_cast<int>(timeout_ms); | ||
| config.ServiceRequestConfig.RetryTimes = reinterpret_cast<int>(retry_times); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 1274680 by clearing the pending exception before returning, so callers no longer continue with an exception in flight (the actual hazard you describe). I kept the
std::stringreturn contract rather than switchingJStringToStdStringtostd::optional/out-param: it's called from many sites, an OOM mid-conversion is the only failure mode here, and the empty-string-on-failure behavior is the established convention. Reworking the signature and every call site is a broader refactor that's out of scope for this null-safety hardening PR.