Skip to content
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

LocateLibrary Filename filter doesn't locate libraries in some instances (Platform$Linux.locateLibrary()). #25

Closed
dkartaschew opened this issue Sep 22, 2014 · 5 comments
Milestone

Comments

@dkartaschew
Copy link

There is an issue with the locateLibrary method in Platform$Linux.locateLibrary() method ( https://github.com/jnr/jnr-ffi/blob/master/src/main/java/jnr/ffi/Platform.java Line 424), in that it only looks for: lib.so or lib.so.[0-9]+. which may miss some instances of libraries that don't follow this convention.

For example, on Debian/Ubuntu, libssl (part of OpenSSL) is installed only as /lib/x86_64-linux-gnu/libssl.so.1.0.0 (eg, https://packages.debian.org/sid/amd64/libssl1.0.0/filelist for full list). The current regex will fail to locate this library.

The obvious temporary work around is to symlink libssl.so.1.0.0 to libssl.so.1 (or just libssl.so), but this will have to be done for all instances of libraries that don't do this already, and makes it painful for software developers having to support multiple OS installations.

While personally I believe this is a distribution issue (for not installing all libraries with the expected convention), JNR should also be smart enough to handle these types of oddities with shared libraries.

I've tested changing the regex pattern to
Pattern p = Pattern.compile("lib" + libName + "\.so(\.[0-9]+)*$");
and this appears to work well, and this new pattern no longer requires testing for an exact match either, as the pattern simple looks for "libssl.so" followed by zero or more ".[0-9]+" number groups. The alternative is to remove the last $ from the original regex pattern, so it doesn't match end of string...

Additionally, when scanning for highest version, the substring() method (line 453) will have to handle the new format (mulitple groups of version digits) as well,
eg
String num = path.substring(path.lastIndexOf(".so.") + 4);
num = num.substring(0, num.indexOf("."));

The above only takes into account the first digit, but this was good enough for our implementations.

@pepijnve
Copy link
Contributor

pepijnve commented Sep 1, 2016

I have the exact same issue with libcrypto.so on Debian/Ubuntu. Only the dev package contains the .so. symlink.
Is there a technical reason to only check for single component version numbers?

@headius
Copy link
Member

headius commented Sep 6, 2016

I agree JNR should be smarter here, but we'd need some assistance fixing it. Someone want to take a stab at a PR?

@pepijnve
Copy link
Contributor

pepijnve commented Sep 6, 2016

I implemented a fix for this in #76
It changes the lookup logic to find all versioned variants of a library and chooses the one with the highest, most precise version number. So 1 > 0, 1.1 > 1.0 and 1.1.0 > 1.1.

@mkristian
Copy link
Contributor

the PR looks good to me

@headius
Copy link
Member

headius commented Sep 26, 2016

Fixed by #76.

@headius headius closed this as completed Sep 26, 2016
@headius headius added this to the 2.1.0 milestone Sep 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants