This PR fixes a bug in `GlassViewDelegate::convertNSStringToJString` where it can return an uninitialized `jstring` value in one case.
The macOS `convertNSStringToJString` function defines a local `jstring jStr` variable and returns it from the function. This variable is not initialized in one code path if the call to malloc fails, so garbage can be returned. Additionally, the length parameter isn't validated and could overflow. The fix for the first problem is to initialize the `jStr` variable to `NULL`, which will be used as the return value in the case where the malloc fails (the caller already handles a `NULL` return value). The fix for the second is a simple check to ensure the value passed to malloc does not overflow. For good measure, I explicitly cast length to (size_t) although that isn't strictly necessary. ------------- Commit messages: - 8381517: GlassViewDelegate::convertNSStringToJString can return uninitialized value Changes: https://git.openjdk.org/jfx/pull/2135/files Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2135&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8381517 Stats: 6 lines in 1 file changed: 4 ins; 0 del; 2 mod Patch: https://git.openjdk.org/jfx/pull/2135.diff Fetch: git fetch https://git.openjdk.org/jfx.git pull/2135/head:pull/2135 PR: https://git.openjdk.org/jfx/pull/2135
