Skip to content

Commit 0a554d1

Browse files
committed
Fix double free in ZIP local header
1 parent fac8164 commit 0a554d1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

appx.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,7 @@ static int zipAppendSignatureFile(BIO *bio, ZIP_FILE *zip, uint8_t *data, uint64
15031503
if (!get_current_position(bio, &offset)) {
15041504
fprintf(stderr, "Unable to get offset\n");
15051505
OPENSSL_free(header.fileName);
1506+
header.fileName = NULL;
15061507
OPENSSL_free(dataToWrite);
15071508
return 0; /* FAILED */
15081509
}
@@ -1513,6 +1514,7 @@ static int zipAppendSignatureFile(BIO *bio, ZIP_FILE *zip, uint8_t *data, uint64
15131514
if (!BIO_write_ex(bio, dataToWrite + written, toWrite, &check)
15141515
|| check != toWrite) {
15151516
OPENSSL_free(header.fileName);
1517+
header.fileName = NULL;
15161518
OPENSSL_free(dataToWrite);
15171519
return 0; /* FAILED */
15181520
}
@@ -1685,6 +1687,8 @@ static int zipRewriteData(ZIP_FILE *zip, ZIP_CENTRAL_DIRECTORY_ENTRY *entry, BIO
16851687
out:
16861688
OPENSSL_free(header.fileName);
16871689
OPENSSL_free(header.extraField);
1690+
header.fileName = NULL;
1691+
header.extraField = NULL;
16881692
return ret;
16891693
}
16901694

@@ -1863,6 +1867,8 @@ static size_t zipReadFileData(ZIP_FILE *zip, uint8_t **pData, ZIP_CENTRAL_DIRECT
18631867
if (!zipReadLocalHeader(&header, zip, compressedSize)) {
18641868
OPENSSL_free(header.fileName);
18651869
OPENSSL_free(header.extraField);
1870+
header.fileName = NULL;
1871+
header.extraField = NULL;
18661872
return 0; /* FAILED */
18671873
}
18681874
if (header.fileNameLen != entry->fileNameLen
@@ -1873,11 +1879,15 @@ static size_t zipReadFileData(ZIP_FILE *zip, uint8_t **pData, ZIP_CENTRAL_DIRECT
18731879
fprintf(stderr, "Local header does not match central directory entry\n");
18741880
OPENSSL_free(header.fileName);
18751881
OPENSSL_free(header.extraField);
1882+
header.fileName = NULL;
1883+
header.extraField = NULL;
18761884
return 0; /* FAILED */
18771885
}
18781886
/* we don't really need those */
18791887
OPENSSL_free(header.fileName);
18801888
OPENSSL_free(header.extraField);
1889+
header.fileName = NULL;
1890+
header.extraField = NULL;
18811891

18821892
if (compressedSize > (uint64_t)zip->fileSize - entry->offsetOfLocalHeader) {
18831893
fprintf(stderr, "Corrupted compressedSize : 0x%08" PRIX64 "\n", entry->compressedSize);
@@ -2011,6 +2021,8 @@ static int zipReadLocalHeader(ZIP_LOCAL_HEADER *header, ZIP_FILE *zip, uint64_t
20112021
fprintf(stderr, "The input file is not a valid zip file - flags indicate data descriptor, but data descriptor signature does not match\n");
20122022
OPENSSL_free(header->fileName);
20132023
OPENSSL_free(header->extraField);
2024+
header->fileName = NULL;
2025+
header->extraField = NULL;
20142026
return 0; /* FAILED */
20152027
}
20162028
header->crc32 = fileGetU32(file);

0 commit comments

Comments
 (0)