Skip to content

Commit fbab2b6

Browse files
zimegClaude
andauthored
fix: avoid infinite loops when searching for filesystem root of another drive (#353)
Co-authored-by: Claude <svc-devxp-claude@slack-corp.com>
1 parent 54ba6d6 commit fbab2b6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

internal/shared/clients.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ func (c *ClientFactory) InitSDKConfig(ctx context.Context, dirPath string) error
222222
return slackerror.New(slackerror.ErrHooksJSONLocation)
223223
}
224224
// Move upward one directory level
225-
dirPath = filepath.Dir(dirPath)
225+
parentDir := filepath.Dir(dirPath)
226+
if parentDir == dirPath {
227+
// Reached a filesystem root not covered above (e.g. D:\ when SYSTEMROOT is on C:\)
228+
return slackerror.New(slackerror.ErrHooksJSONLocation)
229+
}
230+
dirPath = parentDir
226231
}
227232
configFileBytes, err := afero.ReadFile(c.Fs, hooksJSONFilePath)
228233
if err != nil {

internal/shared/clients_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ func Test_ClientFactory_InitSDKConfig(t *testing.T) {
110110
mockWorkingDirectory: filepath.Join("path", "outside", "home", "to", "project"),
111111
expectedError: slackerror.New(slackerror.ErrHooksJSONLocation),
112112
},
113+
"errors if traversal reaches a filesystem root": {
114+
mockHooksJSONContent: "{}",
115+
mockHooksJSONFilePath: filepath.Join(string(filepath.Separator), "other", "volume", "project", "package.json"),
116+
mockWorkingDirectory: filepath.Join(string(filepath.Separator), "other", "volume", "project"),
117+
expectedError: slackerror.New(slackerror.ErrHooksJSONLocation),
118+
},
113119
}
114120
for name, tc := range tests {
115121
t.Run(name, func(t *testing.T) {

0 commit comments

Comments
 (0)