mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8300491: SymbolLookup::libraryLookup accepts strings with terminators
Reviewed-by: psandoz
This commit is contained in:
parent
48d21bd089
commit
534de6d8ae
6 changed files with 38 additions and 0 deletions
|
@ -28,6 +28,7 @@ package java.lang.foreign;
|
|||
import jdk.internal.access.JavaLangAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.foreign.MemorySessionImpl;
|
||||
import jdk.internal.foreign.Utils;
|
||||
import jdk.internal.javac.PreviewFeature;
|
||||
import jdk.internal.loader.BuiltinClassLoader;
|
||||
import jdk.internal.loader.NativeLibrary;
|
||||
|
@ -192,6 +193,7 @@ public interface SymbolLookup {
|
|||
}
|
||||
return name -> {
|
||||
Objects.requireNonNull(name);
|
||||
if (Utils.containsNullChars(name)) return Optional.empty();
|
||||
JavaLangAccess javaLangAccess = SharedSecrets.getJavaLangAccess();
|
||||
// note: ClassLoader::findNative supports a null loader
|
||||
long addr = javaLangAccess.findNative(loader, name);
|
||||
|
@ -229,6 +231,9 @@ public interface SymbolLookup {
|
|||
@CallerSensitive
|
||||
static SymbolLookup libraryLookup(String name, Arena arena) {
|
||||
Reflection.ensureNativeAccess(Reflection.getCallerClass(), SymbolLookup.class, "libraryLookup");
|
||||
if (Utils.containsNullChars(name)) {
|
||||
throw new IllegalArgumentException("Cannot open library: " + name);
|
||||
}
|
||||
return libraryLookup(name, RawNativeLibraries::load, arena);
|
||||
}
|
||||
|
||||
|
@ -279,6 +284,7 @@ public interface SymbolLookup {
|
|||
});
|
||||
return name -> {
|
||||
Objects.requireNonNull(name);
|
||||
if (Utils.containsNullChars(name)) return Optional.empty();
|
||||
long addr = library.find(name);
|
||||
return addr == 0L ?
|
||||
Optional.empty() :
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue