fs/LookupFile: check for empty file name on Windows
Fixes crash bug in the (synthetic) unit test. See code comment.
This commit is contained in:
@@ -43,12 +43,30 @@ LookupFile(Path pathname)
|
|||||||
} catch (const std::system_error &e) {
|
} catch (const std::system_error &e) {
|
||||||
if (!IsPathNotFound(e))
|
if (!IsPathNotFound(e))
|
||||||
throw;
|
throw;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (idx == 0)
|
||||||
|
/* on Windows, the semantics are
|
||||||
|
different for empty strings:
|
||||||
|
GetFileAttributesExA() fails with
|
||||||
|
ERROR_PATH_NOT_FOUND, and the
|
||||||
|
IsPathNotFound() check above would
|
||||||
|
not rethrow the exception, but the
|
||||||
|
empty string would lead to an
|
||||||
|
integer overflow in the code below,
|
||||||
|
so we need to make this a special
|
||||||
|
case on Windows */
|
||||||
|
throw;
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//find one dir up
|
//find one dir up
|
||||||
if (slash != nullptr)
|
if (slash != nullptr)
|
||||||
*slash = '/';
|
*slash = '/';
|
||||||
|
|
||||||
|
assert(idx > 0);
|
||||||
|
|
||||||
slash = FindSlash(&buffer.front(), idx - 1);
|
slash = FindSlash(&buffer.front(), idx - 1);
|
||||||
if (slash == nullptr)
|
if (slash == nullptr)
|
||||||
return {};
|
return {};
|
||||||
|
Reference in New Issue
Block a user