Skip to contentSkip to conversation

insane.bbclass: tighten lib_re and exec_re patterns to avoid false positive

PATCH In review Bill Randle 3 participants 8 messages Mar 23, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 insane.bbclass: tighten lib_re and exec_re patterns to avoid false positive

lib_re would match files like "/libsoletta.so.0.0.1-gdb.py" which are not valid library filenames. Tighten up the re for lib_re and exec_re so they match only valid sonames (.so or .so followed by major version and optional minor version and release).

[YOCTO #9215]

---
 meta/classes/insane.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/classes/insane.bbclass +2 -2
index 7ac945d..e60c358 100644
@@ -318,8 +318,8 @@ def package_qa_check_libdir(d):
 
     messages = []
 
-    lib_re = re.compile("^/lib.+\.so(\..+)?$")
-    exec_re = re.compile("^%s.*/lib.+\.so(\..+)?$" % exec_prefix)
+    lib_re = re.compile("^/lib.+\.so(\.\d+){0,3}$")
+    exec_re = re.compile("^%s.*/lib.+\.so(\.\d+){0,3}$" % exec_prefix)
 
     for root, dirs, files in os.walk(pkgdest):
         if root == pkgdest:
Signature · 1 line
2.5.0
#1 lore raw

meta/classes/insane.bbclass def package_qa_check_libdir(d): · line 322

Quoted 3 lines · Bill Randle
meta/classes/insane.bbclass +2 -0
+    lib_re = re.compile("^/lib.+\.so(\.\d+){0,3}$")
+    exec_re = re.compile("^%s.*/lib.+\.so(\.\d+){0,3}$" % exec_prefix)

I worry that this goes too far in the other way, my Debian host has a library called /usr/lib/libblas.so.3gf.

Maybe we should add a "is this an ELF" test into the libdir check instead? That might kill performance though, and this is just a sanity check.

Any other thoughts?

Ross

#2 lore raw

On Wed, 2016-03-23 at 16:23 +0000, Burton, Ross wrote:

On 23 March 2016 at 15:54, Bill Randle <[email protected]<mailto:[email protected]>> wrote:
+ lib_re = re.compile("^/lib.+\.so(\.\d+){0,3}$")
+ exec_re = re.compile("^%s.*/lib.+\.so(\.\d+){0,3}$" % exec_prefix)

I worry that this goes too far in the other way, my Debian host has a library called /usr/lib/libblas.so.3gf.

Maybe we should add a "is this an ELF" test into the libdir check instead? That might kill performance though, and this is just a sanity check.

Any other thoughts?

Ross

Ok, I found a library on my FC23 system named "libdmraid.so.1.0.0.rc16" in /usr/lib64. The available documentation on sonames I found states:

"Every shared library has a special name called the ``soname''. The soname has the prefix ``lib'', the name of the library, the phrase ``.so'', followed by a period and a version number that is incremented whenever the interface changes (as a special exception, the lowest-level C libraries don't start with ``lib''). A fully-qualified soname includes as a prefix the directory it's in; on a working system a fully-qualified soname is simply a symbolic link to the shared library's ``real name''.

"Every shared library also has a ``real name'', which is the filename containing the actual library code. The real name adds to the soname a period, a minor number, another period, and the release number. The last period and release number are optional. The minor number and release number support configuration control by letting you know exactly what version(s) of the library are installed. Note that these numbers might not be the same as the numbers used to describe the library in documentation, although that does make things easier."

That implies there should only be upto three numbers after the .so, to the ".rc16" on the end violates that rule, and the implication is these should be version *numbers*, not version strings, which would mean your library ending in .3gf violates that rule.

I guess some rules are just meant to be broken. Sigh.

-Bill

#3 lore raw
In reply to Bill Randle
Quoted 2 lines · Bill Randle

lib_re would match files like "/libsoletta.so.0.0.1-gdb.py" which are not valid library filenames.

What are the consequences of it matching things that are not libraries?

Quoted 3 lines

Tighten up the re for lib_re and exec_re so they match only valid sonames (.so or .so followed by major version and optional minor version and release).

Where does this definition of "valid sonames" come from?

p.

#4 lore raw
Quoted 4 lines · Phil Blundell
Quoted 2 lines

lib_re would match files like "/libsoletta.so.0.0.1-gdb.py" which are not valid library filenames.

What are the consequences of it matching things that are not libraries?

See #9215, the libdir sanity test fires when it shouldn't.

WARNING: QA Issue: soletta-dbg: found library in wrong location:
/usr/share/gdb/auto-load/libsoletta.so.0.0.1-gdb.py [libdir]

That's no library...

Ross

#5 lore raw
Quoted 6 lines · Ross
Quoted 4 lines · Phil Blundell
Quoted 1 line

lib_re would match files like "/libsoletta.so.0.0.1-gdb.py" which

are

Quoted 1 line

not valid library filenames.

Quoted 8 lines
Quoted 2 lines

What are the consequences of it matching things that are not libraries?

See #9215, the libdir sanity test fires when it shouldn't.

WARNING: QA Issue: soletta-dbg: found library in wrong location:
/usr/share/gdb/auto-load/libsoletta.so.0.0.1-gdb.py [libdir]

That's no library...

Ah, right. I see.
I wonder if we should just give insane.bbclass a whitelist of directories in which it should ignore apparently misplaced libraries. There aren't likely to be many cases like that one.
Or alternatively, add an extra check so that when it thinks it's found a misplaced library, it checks the ELF header to make sure that it really is one and suppresses the diagnostic if not.  If you only do this in cases where it was about to print a warning anyway then the impact on performance shouldn't be too bad.
p.

#6 lore raw
Quoted 6 lines · Phil Blundell

Or alternatively, add an extra check so that when it thinks it's found a misplaced library, it checks the ELF header to make sure that it really is one and suppresses the diagnostic if not. If you only do this in cases where it was about to print a warning anyway then the impact on performance shouldn't be too bad.

Yeah, best of both worlds. A flexible regex to catch potential offenders, and then use oe.qa.ELFFile to verify it's actually a library. Can you update the patch Bill?

Ross

#7 lore raw
Quoted 8 lines · Ross
Quoted 6 lines · Phil Blundell

Or alternatively, add an extra check so that when it thinks it's found a misplaced library, it checks the ELF header to make sure that it really is one and suppresses the diagnostic if not.  If you only do this in cases where it was about to print a warning anyway then the impact on performance shouldn't be too bad.

Quoted 4 lines

Yeah, best of both worlds.  A flexible regex to catch potential offenders, and then use oe.qa.ELFFile to verify it's actually a library.  Can you update the patch Bill?

Yes, I'll update the patch and repost in a bit.

    -Bill