fix memoryleak in pk3 verify functions

This commit is contained in:
Alug committed 2025-07-24 16:27:16 +02:00
1 parent 7479c82691
commit 1faa585e83
1 file changed
+35 -2
+35 -2
View File
@@ -2039,8 +2039,7 @@ static lumpchecklist_t folderblacklist[] =
{NULL, 0},
};
static int
W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status)
static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status)
{
int verified = true;
@@ -2082,7 +2081,10 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status)
char *cdir = (char*)(malloc(LONG(zend.cdirsize)));
if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize)))
{
free(cdir);
return true;
}
size_t offset = 0;
@@ -2094,7 +2096,10 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status)
char* dotpos;
if (memcmp(zentry->signature, pat_central, 4) != 0)
{
free(cdir);
return true;
}
if (verified == true)
{
@@ -2132,10 +2137,16 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status)
sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen);
if (fseek(fp, LONG(zentry->offset), SEEK_SET) != 0)
{
free(cdir);
return true;
}
if (fread(&zlentry, 1, sizeof(zlentry_t), fp) < sizeof (zlentry_t))
{
free(cdir);
return true;
}
data_size +=
sizeof zlentry + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen) + LONG(zlentry.compsize);
@@ -2186,7 +2197,9 @@ static int W_VerifyFile(const char *filename, lumpchecklist_t *checklist,
goodfile = W_VerifyWAD(handle, checklist, status);
}
}
fclose(handle);
return goodfile;
}
@@ -2341,7 +2354,10 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist)
char *cdir = (char*)(malloc(LONG(zend.cdirsize)));
if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize)))
{
free(cdir);
return true;
}
size_t offset = 0;
@@ -2353,7 +2369,10 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist)
char* dotpos;
if (memcmp(zentry->signature, pat_central, 4) != 0)
{
free(cdir);
return false;
}
fullname = (char*)(malloc(SHORT(zentry->namelen) + 1));
strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1);
@@ -2373,11 +2392,19 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist)
strncpy(lumpname, trimname, min(8, dotpos - trimname));
if (W_NameStartsWith(lumpname, checklist))
{
free(fullname);
free(cdir);
return true;
}
}
if (W_NameStartsWith(fullname, checklist))
{
free(fullname);
free(cdir);
return true;
}
free(fullname);
@@ -2387,10 +2414,16 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist)
sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen);
if (fseek(fp, LONG(zentry->offset), SEEK_SET) != 0)
{
free(cdir);
return false;
}
if (fread(&zlentry, 1, sizeof(zlentry_t), fp) < sizeof (zlentry_t))
{
free(cdir);
return false;
}
data_size +=
sizeof zlentry + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen) + LONG(zlentry.compsize);