From 00089f9cc301f9c3ef09ea630c2fac1843c66f09 Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Fri, 13 Oct 2017 17:13:17 +0200 Subject: [PATCH] NFI Context lookupNativeFunction: avoid potential NPEs --- .../truffle/r/ffi/impl/nfi/TruffleNFI_Context.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java index c90fbc6920..2e79a9dca8 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nfi/TruffleNFI_Context.java @@ -123,9 +123,17 @@ final class TruffleNFI_Context extends RFFIContext { if (function.getLibrary() == NativeFunction.baseLibrary()) { dllInfo = TruffleNFI_Context.getInstance().defaultLibrary; } else if (function.getLibrary() == NativeFunction.anyLibrary()) { - dllInfo = ((NFIHandle) DLL.findLibraryContainingSymbol(function.getCallName()).handle).libHandle; + DLLInfo lib = DLL.findLibraryContainingSymbol(function.getCallName()); + if (lib == null) { + throw RInternalError.shouldNotReachHere("Could not find library containing symbol " + function.getCallName()); + } + dllInfo = ((NFIHandle) lib.handle).libHandle; } else { - dllInfo = ((NFIHandle) DLL.findLibrary(function.getLibrary()).handle).libHandle; + DLLInfo lib = DLL.findLibrary(function.getLibrary()); + if (lib == null) { + throw RInternalError.shouldNotReachHere("Could not find library " + function.getLibrary()); + } + dllInfo = ((NFIHandle) lib.handle).libHandle; } try { TruffleObject symbol = ((TruffleObject) ForeignAccess.sendRead(Message.READ.createNode(), dllInfo, function.getCallName())); -- GitLab