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

Mark Hatle mark.hatle at windriver.com
Fri Dec 1 17:43:30 UTC 2017


On 12/1/17 9:50 AM, Olof Johansson 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:

The original implementation did not include the ',' options because different
versions of file (as well as different architectures) would return different
strings.

They all contains the same information, but order and inclusion of ',' changed
regularly.

So I would caution that for this to check out a wide variety of host systems and
architectures would need to be verified.  (It's very possible that all modern
systems now conform to a single standard...)

(The rest of the serious looks like a very good improvement, and I've got no
further comments on that.)

--Mark

>          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
>  
> 




More information about the Openembedded-core mailing list