JonathonReinhart / staticx

Create static executable from dynamic executable
https://staticx.readthedocs.io/
Other
345 stars 37 forks source link

[BUG] [v0.13.5] gen.add_library() method is called before self.tmpdir is created #216

Closed diegofmole closed 2 years ago

diegofmole commented 2 years ago

In version v0.13.5, main module call the generate one in api.py and that method never execute this line: https://github.com/JonathonReinhart/staticx/blob/v0.13.5/staticx/api.py#L133 So then, when gen.add_library() is called, it fails on this other line with this msg TypeError: expected str, bytes or os.PathLike object, not NoneType as None is the value assigned when the StaticxGenerator is created

Here the output I'm getting:

root@95863632cb84:/src# PYTHONPATH=./packages python3.8 -m staticx -l /lib/x86_64-linux-gnu/libnss_dns-2.27.so -l /lib/x86_64-linux-gnu/libresolv-2.27.so --strip /src/dist/myapp /strip/dist/myapp --loglevel DEBUG
INFO:root:Running StaticX version 0.13.5
INFO:root:Libraries:
INFO:root:  elftools: 0.27
DEBUG:root:External tools:
INFO:root:  ldd: /usr/bin/ldd: ldd (Ubuntu GLIBC 2.27-3ubuntu1.4) 2.27
INFO:root:  objcopy: /usr/bin/objcopy: GNU objcopy (GNU Binutils for Ubuntu) 2.30
INFO:root:  strip: /usr/bin/strip: GNU strip (GNU Binutils for Ubuntu) 2.30
INFO:root:  patchelf: /usr/bin/patchelf: patchelf 0.9
DEBUG:root:Arguments:
DEBUG:root:  prog:      '/src/dist/myapp'
DEBUG:root:  output:    '/strip/dist/myapp'
DEBUG:root:  libs:      ['/lib/x86_64-linux-gnu/libnss_dns-2.27.so', '/lib/x86_64-linux-gnu/libresolv-2.27.so']
DEBUG:root:  strip:     True
DEBUG:root:  compress:  True
DEBUG:root:  debug:     False
INFO:root:Using XZ BCJ filter FILTER_X86
INFO:root:Processing library libnss_dns-2.27.so (/lib/x86_64-linux-gnu/libnss_dns-2.27.so)
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/src/packages/staticx/__main__.py", line 65, in <module>
    main()
  File "/src/packages/staticx/__main__.py", line 51, in main
    generate(args.prog, args.output,
  File "/src/packages/staticx/api.py", line 320, in generate
    gen.add_library(lib)
  File "/src/packages/staticx/api.py", line 202, in add_library
    work_on_copy()
  File "/src/packages/staticx/api.py", line 182, in work_on_copy
    tmplib = os.path.join(self.tmpdir, basename(libpath))
  File "/usr/lib/python3.8/posixpath.py", line 76, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

I also debug this by putting several prints in the api.py module and I saw that it never pass through this method that it's where the self.tmpdir is instanciated.

JonathonReinhart commented 2 years ago

Hi @diegofmole, thanks for the bug report. I fixed this in #217, and released StaticX v0.13.6.

JonathonReinhart commented 2 years ago
python3.8 -m staticx -l /lib/x86_64-linux-gnu/libnss_dns-2.27.so -l /lib/x86_64-linux-gnu/libresolv-2.27.so --strip /src/dist/myapp /strip/dist/myapp --loglevel DEBUG

I must ask, why are you using -l .../libnss_dns-2.27.so -l .../libresolv-2.27.so to manually add these libc libraries? This should not be needed since v0.11.0, where #139 made it unnecessary (via nssfix). I have a couple requests: