mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-19 09:43:20 +00:00
Added bounds check
This commit is contained in:
@@ -8965,7 +8965,7 @@ char *ILibString_ToLower(const char *inString, size_t length)
|
|||||||
int ILibReadFileFromDiskEx(char **Target, char *FileName)
|
int ILibReadFileFromDiskEx(char **Target, char *FileName)
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int SourceFileLength;
|
int SourceFileLength = 0;
|
||||||
FILE *SourceFile = NULL;
|
FILE *SourceFile = NULL;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -8976,12 +8976,15 @@ int ILibReadFileFromDiskEx(char **Target, char *FileName)
|
|||||||
if (SourceFile == NULL) { *Target = NULL; return 0; }
|
if (SourceFile == NULL) { *Target = NULL; return 0; }
|
||||||
|
|
||||||
fseek(SourceFile, 0, SEEK_END);
|
fseek(SourceFile, 0, SEEK_END);
|
||||||
SourceFileLength = (int)ftell(SourceFile);
|
if (ftell(SourceFile) < INT32_MAX) { SourceFileLength = (int)ftell(SourceFile); }
|
||||||
if (SourceFileLength >= 0)
|
if (SourceFileLength >= 0)
|
||||||
{
|
{
|
||||||
fseek(SourceFile, 0, SEEK_SET);
|
fseek(SourceFile, 0, SEEK_SET);
|
||||||
if ((buffer = (char*)malloc(SourceFileLength + 1)) == NULL) ILIBCRITICALEXIT(254);
|
if ((buffer = (char*)malloc(SourceFileLength + 1)) == NULL) ILIBCRITICALEXIT(254);
|
||||||
|
if (SourceFileLength > 0)
|
||||||
|
{
|
||||||
SourceFileLength = (int)fread(buffer, sizeof(char), (size_t)SourceFileLength, SourceFile);
|
SourceFileLength = (int)fread(buffer, sizeof(char), (size_t)SourceFileLength, SourceFile);
|
||||||
|
}
|
||||||
buffer[SourceFileLength] = 0; // To be nice, we allocated one more byte and put a zero at the end.
|
buffer[SourceFileLength] = 0; // To be nice, we allocated one more byte and put a zero at the end.
|
||||||
fclose(SourceFile);
|
fclose(SourceFile);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user