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

Fix Windows-specific problem to determine the real path near a drive root #4253

Merged
merged 2 commits into from
Jan 28, 2023

Conversation

dscho
Copy link
Member

@dscho dscho commented Jan 27, 2023

This PR fixes a pretty fundamental problem where win32_strbuf_realpath() mishandled non-existing paths that are close to the drive root, e.g. C:/foo.

This fixes #4200

dscho added 2 commits January 27, 2023 10:57
It is possible (and supported) that `strbuf_realpath()` can work
in-place, i.e. the second parameter passed to the function can refer to
the `buf` field of the first parameter.

Our code was ill-prepared for that, though: we first store a pointer to
the last component (that does not necessarily need to exist) before
calling the `GetFinalPathNameByHandleW()` function. Said function is
totally allowed to produce a longer path than the original one (e.g. by
prefixing it with `\\?\`, a relatively unintuitive Windows-only
concept). Which would overwrite the last component part.

Address that by making a full string copy of the last component.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Let's be careful to make this function work near the drive root: to
resolve the drive root path itself, we _need_ a trailing backslash:
if a file handle to the path `C:` is created, it does not actually refer
to the drive root. Instead, it refers to this very Windows-only concept
of a "per-drive current directory".

This also requires the code that wants to re-append the last component
to be more careful and only append a slash _if necessary_.

This commit fixes the problem with `scalar unregister C:/foo` that was
reported at git-for-windows#4200.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Copy link

@derrickstolee derrickstolee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tracking down this tricky bug!

@dscho dscho merged commit 10a93f8 into git-for-windows:main Jan 28, 2023
@dscho dscho deleted the fix-win-real-path-near-drive-root branch January 28, 2023 07:18
@dscho dscho added this to the Next release milestone Feb 1, 2023
@dscho dscho mentioned this pull request Feb 27, 2023
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.

"scalar unregister" cannot work against a registered but non-existing enlistment with its absolute path.
2 participants