Skip to content

Commit 048ae80

Browse files
committed
Fix error executing in chroot in Ubuntu container
When Tern ran in a Ubuntu container for images with an `apk` package manager, there was an issue finding the shell which led to a failed package metadata command using chroot. This commit adds a workaround to make sure Tern can find a shell when running in a Ubuntu container, specifically when the shell is symlinked to busybox for the container being analyzed. A more detailed description of the problem can be found in the bug report[1]. It's unclear exactly why the realpath fails to resolve to the correct utility location when Tern runs in a Ubuntu container while analyzing apk-based container images. For now, this commit is meant as a workaround for this exceptional case that is blocking several users. [1]#1161 Resolves #1161 Signed-off-by: Rose Judge <[email protected]>
1 parent 27868a3 commit 048ae80

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tern/analyze/default/default_common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def find_shell(fspath):
3434
if realpath[0] == '/' and os.path.exists(os.path.join(fspath,
3535
realpath[1:])):
3636
return sh
37+
# In some cases, the realpath for a symlink incorrectly resolves to
38+
# /usr/<path>. In these cases, ignore the /usr/ prefix and look for
39+
# the linked binary in the current working dir.
40+
# See issue #1161 for details.
41+
if realpath[0] == '/' and os.path.exists(os.path.join(fspath,
42+
realpath[5:])):
43+
return sh
3744
# otherwise, just follow symlink in same folder and
3845
# remove leading forwardslash before joining paths
3946
if os.path.exists(os.path.join(fspath, sh[1:])):

0 commit comments

Comments
 (0)