Skip to content

Commit

Permalink
Merge pull request #225 from JonathonReinhart/223-libname-symlink
Browse files Browse the repository at this point in the history
Ignore the case where a library symlink has the same basename as its target
  • Loading branch information
JonathonReinhart authored Aug 7, 2022
2 parents 819d8ea + 665a987 commit cbec08b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]
### Fixed
- Fixed an issue where library symlinks with the same basename would present
problems ([#225])

## [0.13.6] - 2021-12-02
### Changed
- Change `--debug` option to appear in CLI help output
Expand Down Expand Up @@ -299,3 +304,4 @@ Initial release
[#208]: https://github.com/JonathonReinhart/staticx/pull/208
[#210]: https://github.com/JonathonReinhart/staticx/pull/210
[#217]: https://github.com/JonathonReinhart/staticx/pull/217
[#225]: https://github.com/JonathonReinhart/staticx/pull/225
12 changes: 10 additions & 2 deletions staticx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,19 @@ def _handle_lib_symlinks(self, libpath):
while islink(libpath):
arcname = basename(libpath)
libpath = get_symlink_target(libpath)
target = basename(libpath)

# Skip symlinks that point to a file with the same name but in a
# different path. We strip path info (and keep just basenames) so
# this would be self-referential.
if arcname == target:
continue

# Add a symlink.
# At this point the target probably doesn't exist, but that doesn't matter yet.
logging.info("Adding Symlink {} => {}".format(arcname, basename(libpath)))
self.sxar.add_symlink(arcname, basename(libpath))
logging.info("Adding Symlink {} => {}".format(arcname, target))
self.sxar.add_symlink(arcname, target)

if arcname in self._added_libs:
raise InternalError("libname {} absent from _added_libs but"
" symlink {} present".format(libname, arcname))
Expand Down
2 changes: 2 additions & 0 deletions staticx/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def close(self):

def add_symlink(self, name, target):
"""Add a symlink to the archive"""
if name == target:
raise ValueError("Refusing to add self-referential symlink")
t = tarfile.TarInfo()
t.type = tarfile.SYMTYPE
t.name = name
Expand Down

0 comments on commit cbec08b

Please sign in to comment.