@@ -1488,6 +1488,7 @@ static int zipAppendSignatureFile(BIO *bio, ZIP_FILE *zip, uint8_t *data, uint64
14881488
14891489 if (!get_current_position (bio , & offset )) {
14901490 fprintf (stderr , "Unable to get offset\n" );
1491+ OPENSSL_free (header .fileName );
14911492 OPENSSL_free (dataToWrite );
14921493 return 0 ; /* FAILED */
14931494 }
@@ -1497,6 +1498,7 @@ static int zipAppendSignatureFile(BIO *bio, ZIP_FILE *zip, uint8_t *data, uint64
14971498 size_t check ;
14981499 if (!BIO_write_ex (bio , dataToWrite + written , toWrite , & check )
14991500 || check != toWrite ) {
1501+ OPENSSL_free (header .fileName );
15001502 OPENSSL_free (dataToWrite );
15011503 return 0 ; /* FAILED */
15021504 }
@@ -1591,6 +1593,7 @@ static int zipRewriteData(ZIP_FILE *zip, ZIP_CENTRAL_DIRECTORY_ENTRY *entry, BIO
15911593{
15921594 size_t check ;
15931595 ZIP_LOCAL_HEADER header ;
1596+ int ret = 0 ;
15941597
15951598 memset (& header , 0 , sizeof (header ));
15961599 if (entry -> offsetOfLocalHeader >= (uint64_t )zip -> fileSize ) {
@@ -1601,7 +1604,7 @@ static int zipRewriteData(ZIP_FILE *zip, ZIP_CENTRAL_DIRECTORY_ENTRY *entry, BIO
16011604 return 0 ; /* FAILED */
16021605 }
16031606 if (!zipReadLocalHeader (& header , zip , entry -> compressedSize )) {
1604- return 0 ; /* FAILED */
1607+ goto out ;
16051608 }
16061609 if (entry -> overrideData ) {
16071610 header .compressedSize = entry -> overrideData -> compressedSize ;
@@ -1612,14 +1615,14 @@ static int zipRewriteData(ZIP_FILE *zip, ZIP_CENTRAL_DIRECTORY_ENTRY *entry, BIO
16121615 if (entry -> overrideData ) {
16131616 if (!BIO_write_ex (bio , entry -> overrideData -> data , entry -> overrideData -> compressedSize , & check )
16141617 || check != entry -> overrideData -> compressedSize ) {
1615- return 0 ; /* FAILED */
1618+ goto out ;
16161619 }
16171620 if (entry -> compressedSize > (uint64_t )zip -> fileSize - entry -> offsetOfLocalHeader ) {
16181621 fprintf (stderr , "Corrupted compressedSize : 0x%08" PRIX64 "\n" , entry -> compressedSize );
1619- return 0 ; /* FAILED */
1622+ goto out ;
16201623 }
16211624 if (fseeko (zip -> file , (int64_t )entry -> compressedSize , SEEK_CUR ) < 0 ) {
1622- return 0 ; /* FAILED */
1625+ goto out ;
16231626 }
16241627 * sizeOnDisk += entry -> overrideData -> compressedSize ;
16251628 } else {
@@ -1630,12 +1633,12 @@ static int zipRewriteData(ZIP_FILE *zip, ZIP_CENTRAL_DIRECTORY_ENTRY *entry, BIO
16301633 size_t size = fread (data , 1 , toWrite , zip -> file );
16311634 if (size != toWrite ) {
16321635 OPENSSL_free (data );
1633- return 0 ; /* FAILED */
1636+ goto out ;
16341637 }
16351638 if (!BIO_write_ex (bio , data , toWrite , & check )
16361639 || check != toWrite ) {
16371640 OPENSSL_free (data );
1638- return 0 ; /* FAILED */
1641+ goto out ;
16391642 }
16401643 * sizeOnDisk += toWrite ;
16411644 len -= toWrite ;
@@ -1654,19 +1657,21 @@ static int zipRewriteData(ZIP_FILE *zip, ZIP_CENTRAL_DIRECTORY_ENTRY *entry, BIO
16541657 }
16551658 if (zip -> isZip64 ) {
16561659 if (fseeko (zip -> file , 24 , SEEK_CUR ) < 0 ) {
1657- return 0 ; /* FAILED */
1660+ goto out ;
16581661 }
16591662 * sizeOnDisk += 24 ;
16601663 } else {
16611664 if (fseeko (zip -> file , 16 , SEEK_CUR ) < 0 ) {
1662- return 0 ; /* FAILED */
1665+ goto out ;
16631666 }
16641667 * sizeOnDisk += 16 ;
16651668 }
16661669 }
1670+ ret = 1 ; /* OK */
1671+ out :
16671672 OPENSSL_free (header .fileName );
16681673 OPENSSL_free (header .extraField );
1669- return 1 ; /* OK */
1674+ return ret ;
16701675}
16711676
16721677/*
@@ -1835,6 +1840,8 @@ static size_t zipReadFileData(ZIP_FILE *zip, uint8_t **pData, ZIP_CENTRAL_DIRECT
18351840 uncompressedSize = entry -> uncompressedSize ;
18361841 memset (& header , 0 , sizeof (header ));
18371842 if (!zipReadLocalHeader (& header , zip , compressedSize )) {
1843+ OPENSSL_free (header .fileName );
1844+ OPENSSL_free (header .extraField );
18381845 return 0 ; /* FAILED */
18391846 }
18401847 if (header .fileNameLen != entry -> fileNameLen
@@ -1843,6 +1850,8 @@ static size_t zipReadFileData(ZIP_FILE *zip, uint8_t **pData, ZIP_CENTRAL_DIRECT
18431850 || header .uncompressedSize != uncompressedSize
18441851 || header .compression != entry -> compression ) {
18451852 fprintf (stderr , "Local header does not match central directory entry\n" );
1853+ OPENSSL_free (header .fileName );
1854+ OPENSSL_free (header .extraField );
18461855 return 0 ; /* FAILED */
18471856 }
18481857 /* we don't really need those */
@@ -2144,6 +2153,7 @@ static int zipDeflate(uint8_t *dest, uint64_t *destLen, uint8_t *source, uLong s
21442153
21452154 err = deflateInit2 (& stream , 8 , Z_DEFLATED , - MAX_WBITS , 8 , Z_DEFAULT_STRATEGY );
21462155 if (err != Z_OK ) {
2156+ deflateEnd (& stream );
21472157 return err ;
21482158 }
21492159 stream .next_out = dest ;
0 commit comments