fixed a potential buffer overrun in Path_WIN32U.cpp (noncritical, as the failing code should never be reached)

This commit is contained in:
Guenter Obiltschnig 2016-08-03 17:25:36 +08:00
parent aed776b7ae
commit a1b8f96111
3 changed files with 15 additions and 3 deletions

View File

@ -129,6 +129,7 @@ std::string PathImpl::tempHomeImpl()
return tempImpl(); return tempImpl();
} }
std::string PathImpl::tempImpl() std::string PathImpl::tempImpl()
{ {
char buffer[MAX_PATH]; char buffer[MAX_PATH];
@ -166,6 +167,7 @@ std::string PathImpl::configImpl()
return result; return result;
} }
std::string PathImpl::nullImpl() std::string PathImpl::nullImpl()
{ {
return "NUL:"; return "NUL:";

View File

@ -139,6 +139,7 @@ std::string PathImpl::tempHomeImpl()
return tempImpl(); return tempImpl();
} }
std::string PathImpl::tempImpl() std::string PathImpl::tempImpl()
{ {
Buffer<wchar_t> buffer(MAX_PATH_LEN); Buffer<wchar_t> buffer(MAX_PATH_LEN);
@ -177,6 +178,7 @@ std::string PathImpl::configImpl()
return result; return result;
} }
std::string PathImpl::nullImpl() std::string PathImpl::nullImpl()
{ {
return "NUL:"; return "NUL:";
@ -203,10 +205,11 @@ std::string PathImpl::expandImpl(const std::string& path)
void PathImpl::listRootsImpl(std::vector<std::string>& roots) void PathImpl::listRootsImpl(std::vector<std::string>& roots)
{ {
roots.clear(); roots.clear();
wchar_t buffer[128]; const int bufferSize = 128;
DWORD n = GetLogicalDriveStringsW(sizeof(buffer)/sizeof(wchar_t) - 1, buffer); wchar_t buffer[bufferSize];
DWORD n = GetLogicalDriveStringsW(bufferSize - 1, buffer);
wchar_t* it = buffer; wchar_t* it = buffer;
wchar_t* end = buffer + (n > sizeof(buffer) ? sizeof(buffer) : n); wchar_t* end = buffer + (n > bufferSize ? bufferSize : n);
while (it < end) while (it < end)
{ {
std::wstring udev; std::wstring udev;

View File

@ -31,36 +31,43 @@ std::string PathImpl::currentImpl()
return("\\"); return("\\");
} }
std::string PathImpl::homeImpl() std::string PathImpl::homeImpl()
{ {
return("\\"); return("\\");
} }
std::string PathImpl::configHomeImpl() std::string PathImpl::configHomeImpl()
{ {
return homeImpl(); return homeImpl();
} }
std::string PathImpl::dataHomeImpl() std::string PathImpl::dataHomeImpl()
{ {
return homeImpl(); return homeImpl();
} }
std::string PathImpl::cacheHomeImpl() std::string PathImpl::cacheHomeImpl()
{ {
return homeImpl(); return homeImpl();
} }
std::string PathImpl::tempHomeImpl() std::string PathImpl::tempHomeImpl()
{ {
return tempImpl(); return tempImpl();
} }
std::string PathImpl::configImpl() std::string PathImpl::configImpl()
{ {
return("\\"); return("\\");
} }
std::string PathImpl::systemImpl() std::string PathImpl::systemImpl()
{ {
return("\\"); return("\\");