Fix panic when bare '@' is passed as a CLI argument#4013
Closed
RonGamzu wants to merge 2 commits into
Closed
Conversation
Passing '@' with no filename causes parseResponseFile to call ReadFile with an empty string, which panics deep in the vfs layer. Guard against it by checking for an empty fileName up front and emitting a Cannot_read_file diagnostic instead. Adds a regression test for this case. Fixes microsoft#3758
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a CLI crash in tsgo when a bare @ is passed (response-file prefix with no filename) by converting the panic into a normal compiler diagnostic, and adds a regression test to ensure the behavior remains non-panicking.
Changes:
- Add an early guard in
parseResponseFileto handle an empty response-file name and emitCannot_read_fileinstead of calling into the VFS with an invalid path. - Add a unit test that invokes
ParseCommandLinewith["@"]and asserts an error diagnostic is produced.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/tsoptions/commandlineparser.go | Guard against empty response-file names to prevent VFS panics and produce a diagnostic. |
| internal/tsoptions/commandlineparser_test.go | Add regression test covering the bare @ CLI argument case. |
Member
|
Did you read the comments on the issue? #3758 (comment) |
Response files passed as relative paths (e.g. tsgo @BLAH) caused a panic in the vfs layer ('path is not absolute') because ReadFile requires absolute paths. Fix by threading the host's current directory into commandLineParser and resolving the response file name against it before reading, using tspath.CombinePaths which correctly passes through paths that are already absolute. The empty-string case (tsgo @) is still caught up front to avoid silently reading the current directory. Fixes microsoft#3758
Author
|
@RyanCavanaugh I’ve read it over and made a few more edits and adjustments. |
Member
|
Already addressed in #3859 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3758
Problem
Running
tsgo @(an@with no filename) causes a panic deep in thevfs layer:
The
@prefix is the response-file convention:@filemeans "readcompiler arguments from this file." When no filename follows the
@,parseResponseFilereceives an empty string and forwards it tofs.ReadFile(""), which the vfs layer rejects with a panic rather thana recoverable error.
Fix
Add an early guard in
parseResponseFilethat returns aCannot_read_filediagnostic when the filename is empty, consistentwith how every other unreadable-file case is handled in the same
function.
Testing
Added
TestParseCommandLineEmptyResponseFilewhich exercises the@argument directly and asserts a diagnostic is produced instead of a
panic.