Fixes to DosQueryCurrentDir().
This API shouldn't return a drive letter or initial path separator, and also shouldn't leak memory.
This commit is contained in:
1 parent
8047d55bcb
commit
b9a799e22e
1 file changed
+14
-6
+14
-6
@@ -2098,20 +2098,28 @@ APIRET DosQueryCurrentDir(ULONG disknum, PBYTE pBuf, PULONG pcbBuf)
|
||||
return ERROR_NOT_ENOUGH_MEMORY; // this doesn't ever return this error on OS/2.
|
||||
|
||||
const size_t len = strlen(cwd);
|
||||
if ((len + 3) > *pcbBuf) {
|
||||
*pcbBuf = len + 3;
|
||||
if ((len + 1) > *pcbBuf) {
|
||||
*pcbBuf = len + 1;
|
||||
free(cwd);
|
||||
return ERROR_BUFFER_OVERFLOW;
|
||||
} // if
|
||||
|
||||
char *ptr = (char *) pBuf;
|
||||
*(ptr++) = 'C';
|
||||
*(ptr++) = ':';
|
||||
for (char *src = cwd; *src; src++) {
|
||||
|
||||
char *src = cwd;
|
||||
while (*src == '/')
|
||||
src++; // skip initial '/' char.
|
||||
|
||||
while (*src) {
|
||||
const char ch = *src;
|
||||
*(ptr++) = ((ch == '/') ? '\\' : ch);
|
||||
} // for
|
||||
src++;
|
||||
} // while
|
||||
|
||||
*ptr = '\0';
|
||||
|
||||
free(cwd);
|
||||
|
||||
return NO_ERROR;
|
||||
} // DosQueryCurrentDir
|
||||
|
||||
|
||||
Reference in new issue
Block a user