VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Dlgcode.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2022-03-26 20:03:19 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2022-03-26 21:15:11 +0100
commit762065917f3ac47c3bdcacdb608d35b36dfb3973 (patch)
tree7863397c35f5e560c28150879307acec6c18b3d2 /src/Common/Dlgcode.c
parenta0809fe85c2f1bf130c26ff77aea7dac19b6c05f (diff)
downloadVeraCrypt-762065917f3ac47c3bdcacdb608d35b36dfb3973.tar.gz
VeraCrypt-762065917f3ac47c3bdcacdb608d35b36dfb3973.zip
Windows: Add various checks to address Coverity reported issues.
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r--src/Common/Dlgcode.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 9d5c0d06..7b3d2d45 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -611,6 +611,7 @@ char *LoadFile (const wchar_t *fileName, DWORD *size)
char *buf;
DWORD fileSize = INVALID_FILE_SIZE;
HANDLE h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ *size = 0;
if (h == INVALID_HANDLE_VALUE)
return NULL;
@@ -620,8 +621,7 @@ char *LoadFile (const wchar_t *fileName, DWORD *size)
return NULL;
}
- *size = fileSize;
- buf = (char *) calloc (*size + 1, 1);
+ buf = (char *) calloc (fileSize + 1, 1);
if (buf == NULL)
{
@@ -629,11 +629,15 @@ char *LoadFile (const wchar_t *fileName, DWORD *size)
return NULL;
}
- if (!ReadFile (h, buf, *size, size, NULL))
+ if (!ReadFile (h, buf, fileSize, size, NULL))
{
free (buf);
buf = NULL;
}
+ else
+ {
+ buf[*size] = 0; //make coverity happy eventhough buf is guaranteed to be null terminated because of fileSize+1 in calloc call
+ }
CloseHandle (h);
return buf;