REVIEW: GetFileName(): Security checks
This commit is contained in:
parent
53b32f1c20
commit
d93f8eadf8
1 changed files with 4 additions and 3 deletions
|
@ -1838,9 +1838,10 @@ static const char *strprbrk(const char *s, const char *charset)
|
||||||
// Get pointer to filename for a path string
|
// Get pointer to filename for a path string
|
||||||
const char *GetFileName(const char *filePath)
|
const char *GetFileName(const char *filePath)
|
||||||
{
|
{
|
||||||
const char *fileName = strprbrk(filePath, "\\/");
|
const char *fileName = NULL;
|
||||||
|
if (filePath != NULL) fileName = strprbrk(filePath, "\\/");
|
||||||
|
|
||||||
if (!fileName || fileName == filePath) return filePath;
|
if (!fileName || (fileName == filePath)) return filePath;
|
||||||
|
|
||||||
return fileName + 1;
|
return fileName + 1;
|
||||||
}
|
}
|
||||||
|
@ -1853,7 +1854,7 @@ const char *GetFileNameWithoutExt(const char *filePath)
|
||||||
static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH];
|
static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH];
|
||||||
memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH);
|
memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH);
|
||||||
|
|
||||||
strcpy(fileName, GetFileName(filePath)); // Get filename with extension
|
if (filePath != NULL) strcpy(fileName, GetFileName(filePath)); // Get filename with extension
|
||||||
|
|
||||||
int len = strlen(fileName);
|
int len = strlen(fileName);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue