Fix infinite loop in find_dir when reaching root directory#708
Fix infinite loop in find_dir when reaching root directory#708xytovl merged 2 commits intoWiVRn:masterfrom
Conversation
The previous loop condition `not copy.empty()` would never terminate at the filesystem root since root paths (e.g., "/" or "C:\") are never empty and their parent_path() returns themselves.
|
I've not yet nailed down generic steps to reproduce, but try making the path for your OpenVR runtime (the vrclient.so) inaccessible or invalid; it should then attempt to traverse up to You can verify that the server is stuck in this condition with:
Note |
This happens when the OpenVR compat path starts with |
ImSapphire
left a comment
There was a problem hiding this comment.
I think this would be a cleaner fix:
server/main.cpp
Outdated
| static std::filesystem::path find_dir(const std::filesystem::path & d, const std::filesystem::path & needle) | ||
| { | ||
| for (auto copy = d; not copy.empty(); copy = copy.parent_path()) | ||
| for (auto copy = d; ; copy = copy.parent_path()) |
There was a problem hiding this comment.
| for (auto copy = d; ; copy = copy.parent_path()) | |
| for (auto copy = d; copy.has_parent_path(); copy = copy.parent_path()) |
There was a problem hiding this comment.
Though I would've expected it to work, it seems that has_parent_path() returns true even on /. So when I applied this suggested commit and tested on my environment, I again got the same behavior as the original code. However, the condition copy != copy.parent_path() works, and then I was able to remove the if (!copy.has_parent_path() || copy == copy.parent_path()) break;, making it cleaner. I'll commit that version to this PR and you can have a look.
|
Thanks, finally got a chance to test the proposed commit, and left a comment above, and a new commit ^ |
The previous loop condition
not copy.empty()would never terminate at the filesystem root since root paths (e.g., "/" or "C:") are never empty and their parent_path() returns themselves.