RFR: 8313900: Possible NULL pointer access in NativeAudioSpectrum and NativeVideoBuffer

Kevin Rushforth kcr at openjdk.org
Mon Aug 14 17:12:28 UTC 2023


On Mon, 14 Aug 2023 16:46:33 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

>> - Fixed by checking for `NULL` pointer after memory allocation.
>> - In `NativeVideoBuffer` `std::nothrow` was added when allocating `jint` array, so `new` will return `NULL` instead of throwing exception. This done for consistency and also it is not clear how well JNI handles C++ exceptions in this case and what value will Java code get if exception is thrown.
>
> modules/javafx.media/src/main/native/jfxmedia/jni/NativeAudioSpectrum.cpp line 58:
> 
>> 56:     CAudioSpectrum *pSpectrum = (CAudioSpectrum*)jlong_to_ptr(nativeRef);
>> 57:     CJavaBandsHolder *pHolder = new (std::nothrow) CJavaBandsHolder();
>> 58:     if (pHolder == NULL) {
> 
> I see more than one occurrence of (std::nothrow) in the code base where the return value is not checked for NULL (directwrite.cpp, GlassAccessible.cpp, GlassTextRangeProvider.cpp - I did not check beyond *.c* wildcard though, so could be more).
> 
> Do we want to add a null check there?

If so, it's unrelated to this fix.

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1204#discussion_r1293743211


More information about the openjfx-dev mailing list