[all-commits] [llvm/llvm-project] eda99a: [Path] Dix off-by-one in finding filename for win ...
Matheus Izvekov via All-commits
all-commits at lists.llvm.org
Wed Jan 17 18:49:26 PST 2024
Branch: refs/heads/users/mizvekov/bug/sys-path-win-colon
Home: https://github.com/llvm/llvm-project
Commit: eda99a5a78f0eaae60fc5fa9e03d001f465512b8
https://github.com/llvm/llvm-project/commit/eda99a5a78f0eaae60fc5fa9e03d001f465512b8
Author: Matheus Izvekov <mizvekov at gmail.com>
Date: 2024-01-17 (Wed, 17 Jan 2024)
Changed paths:
M llvm/lib/Support/Path.cpp
M llvm/unittests/Support/Path.cpp
Log Message:
-----------
[Path] Dix off-by-one in finding filename for win style paths
This fixes a crash where `path::parent_path` causes an invalid
access on a string upon receiving a path that consists of a single colon.
On Windows machine, with runtime checks enabled build, upon `clang -I: test.cc` produces:
```
Assertion failed: Index < Length && "Invalid index!", file llvm\include\llvm/ADT/StringRef.h, line 232
...
#6 0x00007ff7816201eb `anonymous namespace'::parent_path_end llvm\lib\Support\Path.cpp:144:0
#7 0x00007ff781620135 llvm::sys::path::parent_path(class llvm::StringRef, enum llvm::sys::path::Style) llvm\lib\Support\Path.cpp:470:0
```
Ideally, we can look for the last colon starting from the last
character, but we can instead start from second to last, and handle
empty paths by abusing `0 - 1 == npos`.
More information about the All-commits
mailing list