[OE-core] [PATCH 5/5] lib/oe/package.py: is_elf: Make it less prone to false positives

Burton, Ross ross.burton at intel.com
Mon Dec 4 12:36:42 UTC 2017


You might be interested in some of the patches I've got sitting in
http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=ross/mutb
specifically around "Add new ELF parser".  This adds a fully-featured
Python ELF parser to lib/oe which could be used to inspect the binaries the
way file does, but without having to call and parse the output of file.

Ross

On 1 December 2017 at 15:50, Olof Johansson <olof.johansson at axis.com> wrote:

> Avoid matching substrings that are picked up from paths, for instance.
> Do this by anchoring the tokens we look for (e.g "executable" or "not
> stripped") with whitespace and punctuation.
>
> Submitted with this patch series is a change that adds the use of
> --brief to file. This removes the path prefix to the output, but the
> path can still be included in shebang lines (which file will report as
> something like "a /foo/bar/baz.py script").
>
> Signed-off-by: Olof Johansson <olofjn at axis.com>
> ---
>  meta/lib/oe/package.py | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
> index 976d2ef36c..2bd771cfc5 100644
> --- a/meta/lib/oe/package.py
> +++ b/meta/lib/oe/package.py
> @@ -84,17 +84,17 @@ def is_elf(path, on_error=_is_elf_error):
>          error_cb('"file %s" failed')
>          return
>
> -    if not "ELF" in result:
> +    if not result.startswith("ELF "):
>          return 0
>
>      exec_type = 1
> -    if "not stripped" not in result:
> +    if ", not stripped" not in result:
>          exec_type |= 2
> -    if "executable" in result:
> +    if " executable, " in result:
>          exec_type |= 4
> -    if "shared" in result:
> +    if " shared object, " in result:
>          exec_type |= 8
> -    if "relocatable" in result and is_kernel_module(path):
> +    if "relocatable, " in result and is_kernel_module(path):
>          exec_type |= 16
>      return exec_type
>
> --
> 2.11.0
>
> --
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core at lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/openembedded-core/attachments/20171204/12650f50/attachment-0002.html>


More information about the Openembedded-core mailing list