mirror of
https://github.com/facebook/zstd.git
synced 2025-08-05 19:15:58 +03:00
Fix buffer underflow for null dir1
This commit is contained in:
@@ -870,11 +870,11 @@ static const char * trimPath(const char *pathname)
|
|||||||
|
|
||||||
static char* mallocAndJoin2Dir(const char *dir1, const char *dir2)
|
static char* mallocAndJoin2Dir(const char *dir1, const char *dir2)
|
||||||
{
|
{
|
||||||
const size_t dir1Size = strlen(dir1);
|
|
||||||
const size_t dir2Size = strlen(dir2);
|
|
||||||
char *outDirBuffer, *buffer, trailingChar;
|
|
||||||
|
|
||||||
assert(dir1 != NULL && dir2 != NULL);
|
assert(dir1 != NULL && dir2 != NULL);
|
||||||
|
{ const size_t dir1Size = strlen(dir1);
|
||||||
|
const size_t dir2Size = strlen(dir2);
|
||||||
|
char *outDirBuffer, *buffer;
|
||||||
|
|
||||||
outDirBuffer = (char *) malloc(dir1Size + dir2Size + 2);
|
outDirBuffer = (char *) malloc(dir1Size + dir2Size + 2);
|
||||||
CONTROL(outDirBuffer != NULL);
|
CONTROL(outDirBuffer != NULL);
|
||||||
|
|
||||||
@@ -885,8 +885,7 @@ static char* mallocAndJoin2Dir(const char *dir1, const char *dir2)
|
|||||||
return outDirBuffer;
|
return outDirBuffer;
|
||||||
|
|
||||||
buffer = outDirBuffer + dir1Size;
|
buffer = outDirBuffer + dir1Size;
|
||||||
trailingChar = *(buffer - 1);
|
if (dir1Size > 0 && *(buffer - 1) != PATH_SEP) {
|
||||||
if (trailingChar != PATH_SEP) {
|
|
||||||
*buffer = PATH_SEP;
|
*buffer = PATH_SEP;
|
||||||
buffer++;
|
buffer++;
|
||||||
}
|
}
|
||||||
@@ -894,6 +893,7 @@ static char* mallocAndJoin2Dir(const char *dir1, const char *dir2)
|
|||||||
buffer[dir2Size] = '\0';
|
buffer[dir2Size] = '\0';
|
||||||
|
|
||||||
return outDirBuffer;
|
return outDirBuffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function will return NULL if input srcFileName is not valid name for mirrored output path */
|
/* this function will return NULL if input srcFileName is not valid name for mirrored output path */
|
||||||
|
Reference in New Issue
Block a user