Skip to content

Commit

Permalink
Fixes to DosQueryCurrentDir().
Browse files Browse the repository at this point in the history
This API shouldn't return a drive letter or initial path separator,
and also shouldn't leak memory.
  • Loading branch information
icculus committed Oct 17, 2016
1 parent 8047d55 commit b9a799e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions native/doscalls.c
Expand Up @@ -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

Expand Down

0 comments on commit b9a799e

Please sign in to comment.