ideally it should never reach it, but there was already multiple issues with infinite loop
at following symlinks. this fixes hanging unit tests
Docker-DCO-1.1-Signed-off-by: Lajos Papp <lajos.papp@sequenceiq.com> (github: lalyos)
... | ... |
@@ -3,10 +3,13 @@ package symlink |
3 | 3 |
import ( |
4 | 4 |
"fmt" |
5 | 5 |
"os" |
6 |
+ "path" |
|
6 | 7 |
"path/filepath" |
7 | 8 |
"strings" |
8 | 9 |
) |
9 | 10 |
|
11 |
+const maxLoopCounter = 100 |
|
12 |
+ |
|
10 | 13 |
// FollowSymlink will follow an existing link and scope it to the root |
11 | 14 |
// path provided. |
12 | 15 |
func FollowSymlinkInScope(link, root string) (string, error) { |
... | ... |
@@ -30,7 +33,14 @@ func FollowSymlinkInScope(link, root string) (string, error) { |
30 | 30 |
prev = filepath.Join(prev, p) |
31 | 31 |
prev = filepath.Clean(prev) |
32 | 32 |
|
33 |
+ loopCounter := 0 |
|
33 | 34 |
for { |
35 |
+ loopCounter++ |
|
36 |
+ |
|
37 |
+ if loopCounter >= maxLoopCounter { |
|
38 |
+ return "", fmt.Errorf("loopCounter reached MAX: %v", loopCounter) |
|
39 |
+ } |
|
40 |
+ |
|
34 | 41 |
if !strings.HasPrefix(prev, root) { |
35 | 42 |
// Don't resolve symlinks outside of root. For example, |
36 | 43 |
// we don't have to check /home in the below. |