#6003

update-path.bat corrupts the system PATH when its last entry ends with a backslash

Opencleverlieopened 3d ago

Is there an existing issue for this?

  • I have searched the existing issues

Is your issue described in the documentation?

  • I have read the documentation

Is your issue present in the latest beta/pre-release?

This issue is present in the latest pre-release

Describe the Bug

update-path.bat remove writes the PATH back with:

reg add "%KEY_NAME%" /v "%VALUE_NAME%" /t REG_EXPAND_SZ /f /d "!CURRENT_PATH!"

If the last PATH entry ends with a backslash, the command line ends in \". Windows command-line parsing treats \" as an escaped literal quote, so reg.exe stores the last entry with a " in place of the backslash.

PATH values ending in a backslash are common: MSI packages that append [INSTALLDIR] to PATH always write a trailing backslash. On my machine the WSL 3.0.3.0 MSI had appended C:\Program Files\WSL\ as the last entry. After uninstalling Sunshine it became C:\Program Files\WSL".

Consequences:

  • The system PATH holds an entry with an invalid path character. .NET System.IO.Path methods throw "Illegal characters in path" on it, which broke unrelated tooling that scans PATH.
  • The next update-path.bat add (the reinstall one minute later) fails with ERROR: Invalid syntax., because the stray quote breaks its own reg add command line. Sunshine's directories are not added to PATH.

The setup logs are in the Log output field below.

The parsing rule reproduces with any program that uses the standard C runtime argument parser:

> python -c "import sys; print(sys.argv[1:])" /d "C:\Windows;C:\Program Files\WSL\"
['/d', 'C:\\Windows;C:\\Program Files\\WSL"']

Steps to reproduce:

  1. Make the last entry of the system PATH end with a backslash, for example by appending C:\Temp\.
  2. Install Sunshine. Its two directories are appended after C:\Temp\.
  3. Uninstall Sunshine. C:\Temp\ is the last entry again and is written back as C:\Temp".

Expected Behavior

The uninstaller removes Sunshine's two directories and leaves every other PATH entry byte-for-byte unchanged.

Additional Context

src_assets/windows/misc/path/update-path.bat on master is identical to the copy shipped in 2026.914.233613.

The uninstall that rewrote the PATH was the Uninstall.exe of an earlier exe-installer build (version not recorded), run by winget uninstall; the reinstall was the 2026.914.233613 MSI.

The remove branch is the one that triggers it; add always ends the value with Sunshine's own directory, which has no trailing backslash.

Possible fix: double a trailing backslash right before each reg add, so the closing quote stays a closing quote:

if "!CURRENT_PATH:~-1!"=="\" set "CURRENT_PATH=!CURRENT_PATH!\"
reg add "%KEY_NAME%" /v "%VALUE_NAME%" /t REG_EXPAND_SZ /f /d "!CURRENT_PATH!"

(same for NEW_PATH in the add branch). \\" parses as one literal backslash followed by the closing quote. Tested with the argument parser above: "C:\Windows;C:\Program Files\WSL\\" gives C:\Windows;C:\Program Files\WSL\.

An alternative that avoids command-line quoting altogether is to do the PATH update from sunshine-setup.ps1 with the .NET registry API (GetValue('Path', $null, 'DoNotExpandEnvironmentNames') and SetValue('Path', $value, 'ExpandString')).

The runtime logs from the web UI are not included: Sunshine's runtime is not involved, the bug is in the installer scripts. The log output below is from the setup scripts (%TEMP%\Sunshine\logs), with the PATH shortened.

Host Operating System

Windows

Operating System Version

Windows 11 Pro 10.0.26200.9457

Architecture

amd64/x86_64

Package

Windows - Winget

GPU Type

NVIDIA

GPU Model

GeForce RTX 3090

GPU Driver/Mesa Version

610.88

Capture Method

No response

Apps

undefined

Log output

# uninstall\20261025_162031.log
Executing: C:\Program Files\Sunshine\scripts\update-path.bat remove
  Current path: ...;C:\Program Files\NVIDIA Corporation\Nsight Compute 2026.3.1\;C:\Program Files\WSL\
  Removing from path: C:\Program Files\Sunshine
  Removing from path: C:\Program Files\Sunshine\tools
  The operation completed successfully.
  Successfully removed Sunshine directories from PATH

# install\20261025_162133.log (one minute later)
Executing: C:\Program Files\Sunshine\scripts\update-path.bat add
  Current path: ...;C:\Program Files\NVIDIA Corporation\Nsight Compute 2026.3.1\;C:\Program Files\WSL"
  Adding to path: C:\Program Files\Sunshine
  Adding to path: C:\Program Files\Sunshine\tools
  Failed to add Sunshine directories to PATH
  ERROR: Invalid syntax.
  Type "REG ADD /?" for usage.

Online logs

No response

Activity

0

No activity yet.