Skip to content

fix(factory): skip symlinks/junctions during directory scan (fixes #690)#952

Open
chirag127 wants to merge 1 commit into
BCUninstaller:masterfrom
chirag127:fix/skip-symlinks-directory-scan
Open

fix(factory): skip symlinks/junctions during directory scan (fixes #690)#952
chirag127 wants to merge 1 commit into
BCUninstaller:masterfrom
chirag127:fix/skip-symlinks-directory-scan

Conversation

@chirag127

Copy link
Copy Markdown

Summary

Skip symbolic links and directory junctions when scanning InstallLocation for executables. Fixes #690.

Problem

BCU currently enumerates .exe files and subdirectories with directory.GetFiles(...) / directory.GetDirectories() and treats each result as if it were regular content. If a symlink or junction points at another location, BCU:

  1. Adds a duplicate entry pointing at the linked target
  2. In the worst case (link points back inside the scan tree), recurses into the same content the parent scan already covered

Report: #690.

Fix

In AppExecutablesSearcher.ScanDirectory:

  • Filter top-level .exe matches with (f.Attributes & FileAttributes.ReparsePoint) == 0
  • Filter .exe matches inside recognised binary subdirectories with the same check
  • Skip whole subdirectories that are reparse points before recursing / classifying them

FileAttributes.ReparsePoint covers symlinks (created with mklink / New-Item -ItemType SymbolicLink) and directory junctions (created with mklink /J).

Changes

File Δ
source/UninstallTools/Factory/InfoAdders/AppExecutablesSearcher.cs +10, -2

Net 8 lines. No changes to behaviour for regular files/directories.

Test plan

  • Create a scenario with a symlink inside InstallLocation:
    mklink /D "C:\Program Files\SomeApp\linked" "C:\some\other\dir"
    
  • Scan with BCU
  • Before this fix: SortedExecutables includes .exe files from the linked target and duplicates any dupes
  • After: SortedExecutables is unchanged as if linked/ did not exist

Related

…aller#690)

Symbolic links and directory junctions were being enumerated as if they
were regular files/directories, producing duplicate uninstaller entries
and, in the case of a symlink pointing back into the scan tree, risking
unbounded recursion into the same content.

Guard both:
- The .exe file enumeration (both top-level and inside binary subdirs)
  with FileAttributes.ReparsePoint == 0.
- The subdirectory loop with the same check as the first step so we
  don't recurse into linked directories.

Fixes BCUninstaller#690.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exclude symlink as a program

2 participants