Re:What it takes to pass a file path to a Windows API in C++
by cm2187 on Sunday September 24, 2023 @09:05AM
(#37632762)
I never understood what backward compatibility was met by windows api not supporting >260 chars file paths. It will work just in the same was if you pass any short path and no old application expects a long path anyway.
[ Parent
| on HN ]
Re:What it takes to pass a file path to a Windows API in C++
by Someone on Sunday September 24, 2023 @09:37AM
(#37633008)
[delayed]
Re:What it takes to pass a file path to a Windows API in C++
by Arainach on Sunday September 24, 2023 @09:32AM
(#37632967)
Decades of binaries are in use doing something like
``` wchar_t filename[MAX_PATH]; CreateFileW(...) ```
in both first part and third party Windows code, often in deep callstacks passing file names around. Changing the length requires fixing them all.
See comments in https://archives.miloush.net/michkap/archive/2006/12/13/1275...
Re:What it takes to pass a file path to a Windows API in C++
by TonyTrapp on Sunday September 24, 2023 @10:05AM
(#37633245)
Your example isn't problematic API-wise, because CreateFileW doesn't need to care if you pass in 16 characters or 1600 - if it does, that is mostly a matter of refactoring and not inherent to how the function works. The real problem are APIs that inherently assume that you pass in a string of at most MAX_PATH characters, because you provide a pointer but no size, and the API is expected to write to that pointer. This affects most shell32 getter functions, e.g. SHGetKnownFolderPath.
But for functions outside of Windows itself, this is the exact reason why the long path feature is hidden behind an opt-in flag.
Re:What it takes to pass a file path to a Windows API in C++
by mappu on Sunday September 24, 2023 @09:20AM
(#37632865)
MAX_PATH is a #define. So its value is baked in to old binaries.
In RAM-constrained world of the past, you would stack-allocate `char buff[MAX_PATH]` and do all your strcpy/strspn in there with no problems.
Now, if that app receives a long path into a too short buffer, it will instantly stack overflow and may cause exploitable problems.