Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not resolve symbolic links in posix locator if they exceed the count limit #21658

Merged
merged 6 commits into from
Jul 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add additional logging
  • Loading branch information
Kartik Raj committed Jul 19, 2023
commit 1aa768b2e20aa61383a0a50a8921915de85120e7
13 changes: 8 additions & 5 deletions src/client/pythonEnvironments/common/externalDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ export function arePathsSame(path1: string, path2: string): boolean {

export async function resolveSymbolicLink(absPath: string, stats?: fsapi.Stats, count?: number): Promise<string> {
stats = stats ?? (await fsapi.lstat(absPath));
if (count && count > 5) {
traceError(`Too many symbolic links encountered: ${absPath}, stop resolving.`);
return absPath;
}
if (stats.isSymbolicLink()) {
if (count && count > 5) {
traceError(`Too many symbolic links encountered: ${absPath}, stop resolving.`);
return absPath;
}
traceVerbose(`Attempt to resolve symbolic link ${absPath}`);
const link = await fsapi.readlink(absPath);
count = count ? count + 1 : 1;
traceVerbose(`Resolved symbolic link to ${absPath} -> ${link}`);
// Result from readlink is not guaranteed to be an absolute path. For eg. on Mac it resolves
// /usr/local/bin/python3.9 -> ../../../Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
//
// The resultant path is reported relative to the symlink directory we resolve. Convert that to absolute path.
const absLinkPath = path.isAbsolute(link) ? link : path.resolve(path.dirname(absPath), link);
return resolveSymbolicLink(absLinkPath, undefined, count ?? 0 + 1);
return resolveSymbolicLink(absLinkPath, undefined, count);
}
return absPath;
}
Expand Down
Loading