Skip to content

Commit

Permalink
Test if busybox is not dynamically linked
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Aug 11, 2023
1 parent 7194587 commit f3b6825
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions gns3server/compute/docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self):
self._api_version = DOCKER_MINIMUM_API_VERSION

@staticmethod
def install_busybox():
async def install_busybox():

if not sys.platform.startswith("linux"):
return
Expand All @@ -69,10 +69,24 @@ def install_busybox():
for busybox_exec in ("busybox-static", "busybox.static", "busybox"):
busybox_path = shutil.which(busybox_exec)
if busybox_path:
log.info(f"Installing busybox from '{busybox_path}'")
try:
shutil.copy2(busybox_path, dst_busybox, follow_symlinks=True)
return
# check that busybox is statically linked
# (dynamically linked busybox will fail to run in a container)
proc = await asyncio.create_subprocess_exec(
"ldd",
busybox_path,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.DEVNULL
)
stdout, _ = await proc.communicate()
if proc.returncode == 1:
# ldd returns 1 if the file is not a dynamic executable
log.info(f"Installing busybox from '{busybox_path}' to '{dst_busybox}'")
shutil.copy2(busybox_path, dst_busybox, follow_symlinks=True)
return
else:
log.warning(f"Busybox '{busybox_path}' is dynamically linked\n"
f"{stdout.decode('utf-8', errors='ignore').strip()}")
except OSError as e:
raise DockerError(f"Could not install busybox: {e}")
raise DockerError("No busybox executable could be found")
Expand Down
2 changes: 1 addition & 1 deletion gns3server/compute/docker/docker_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ async def start(self):
"""

# make sure busybox is installed
self.manager.install_busybox()
await self.manager.install_busybox()

try:
state = await self._get_container_state()
Expand Down
2 changes: 1 addition & 1 deletion gns3server/utils/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def subprocess_check_output(*args, cwd=None, env=None, stderr=False):
if output is None:
return ""
# If we received garbage we ignore invalid characters
# it should happens only when user try to use another binary
# it should happen only when user try to use another binary
# and the code of VPCS, dynamips... Will detect it's not the correct binary
return output.decode("utf-8", errors="ignore")

Expand Down

0 comments on commit f3b6825

Please sign in to comment.