Skip to content

Commit 105fd3a

Browse files
olszomalmtrojnar
authored andcommitted
Fix handling of printf format specifiers
1 parent 86a594b commit 105fd3a

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

appx.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@
1717
#include <zlib.h>
1818
#include <inttypes.h>
1919

20+
#ifndef PRIX64
21+
#if defined(_MSC_VER)
22+
#define PRIX64 "I64X"
23+
#else /* _MSC_VER */
24+
#if ULONG_MAX == 0xFFFFFFFFFFFFFFFF
25+
#define PRIX64 "lX"
26+
#else /* ULONG_MAX == 0xFFFFFFFFFFFFFFFF */
27+
#define PRIX64 "llX"
28+
#endif /* ULONG_MAX == 0xFFFFFFFFFFFFFFFF */
29+
#endif /* _MSC_VER */
30+
#endif /* PRIX64 */
31+
2032
#if defined(_MSC_VER)
2133
#define fseeko _fseeki64
2234
#define ftello _ftelli64
23-
#endif
35+
#endif /* _MSC_VER */
2436

2537
#define EOCDR_SIZE 22
2638
#define ZIP64_EOCD_LOCATOR_SIZE 20
@@ -1605,7 +1617,7 @@ static int zipRewriteData(ZIP_FILE *zip, ZIP_CENTRAL_DIRECTORY_ENTRY *entry, BIO
16051617

16061618
memset(&header, 0, sizeof(header));
16071619
if (entry->offsetOfLocalHeader >= (uint64_t)zip->fileSize) {
1608-
printf("Corrupted relative offset of local header : 0x%08lX\n", entry->offsetOfLocalHeader);
1620+
printf("Corrupted relative offset of local header : 0x%08" PRIX64 "\n", entry->offsetOfLocalHeader);
16091621
return 0; /* FAILED */
16101622
}
16111623
if (fseeko(zip->file, (int64_t)entry->offsetOfLocalHeader, SEEK_SET) < 0) {
@@ -1626,7 +1638,7 @@ static int zipRewriteData(ZIP_FILE *zip, ZIP_CENTRAL_DIRECTORY_ENTRY *entry, BIO
16261638
return 0; /* FAILED */
16271639
}
16281640
if (entry->compressedSize > (uint64_t)zip->fileSize - entry->offsetOfLocalHeader) {
1629-
printf("Corrupted compressedSize : 0x%08lX\n", entry->compressedSize);
1641+
printf("Corrupted compressedSize : 0x%08" PRIX64 "\n", entry->compressedSize);
16301642
return 0; /* FAILED */
16311643
}
16321644
if (fseeko(zip->file, (int64_t)entry->compressedSize, SEEK_CUR) < 0) {
@@ -1829,7 +1841,7 @@ static size_t zipReadFileData(ZIP_FILE *zip, uint8_t **pData, ZIP_CENTRAL_DIRECT
18291841
size_t size, dataSize = 0;
18301842

18311843
if (entry->offsetOfLocalHeader >= (uint64_t)zip->fileSize) {
1832-
printf("Corrupted relative offset of local header : 0x%08lX\n", entry->offsetOfLocalHeader);
1844+
printf("Corrupted relative offset of local header : 0x%08" PRIX64 "\n", entry->offsetOfLocalHeader);
18331845
return 0; /* FAILED */
18341846
}
18351847
if (fseeko(file, (int64_t)entry->offsetOfLocalHeader, SEEK_SET) < 0) {
@@ -1861,7 +1873,7 @@ static size_t zipReadFileData(ZIP_FILE *zip, uint8_t **pData, ZIP_CENTRAL_DIRECT
18611873
OPENSSL_free(header.extraField);
18621874

18631875
if (compressedSize > (uint64_t)zip->fileSize - entry->offsetOfLocalHeader) {
1864-
printf("Corrupted compressedSize : 0x%08lX\n", entry->compressedSize);
1876+
printf("Corrupted compressedSize : 0x%08" PRIX64 "\n", entry->compressedSize);
18651877
return 0; /* FAILED */
18661878
}
18671879
compressedData = OPENSSL_zalloc(compressedSize + 1);
@@ -1978,7 +1990,7 @@ static int zipReadLocalHeader(ZIP_LOCAL_HEADER *header, ZIP_FILE *zip, uint64_t
19781990
return 0; /* FAILED */
19791991
}
19801992
if (compressedSize > (uint64_t)(zip->fileSize - offset)) {
1981-
printf("Corrupted compressedSize : 0x%08lX\n", compressedSize);
1993+
printf("Corrupted compressedSize : 0x%08" PRIX64 "\n", compressedSize);
19821994
return 0; /* FAILED */
19831995
}
19841996
if (fseeko(file, (int64_t)compressedSize, SEEK_CUR) < 0) {
@@ -2218,7 +2230,7 @@ static ZIP_FILE *openZip(const char *filename)
22182230
return NULL; /* FAILED */
22192231
}
22202232
if (zip->locator.eocdOffset >= (uint64_t)zip->fileSize) {
2221-
printf("Corrupted end of central directory locator offset : 0x%08lX\n", zip->locator.eocdOffset);
2233+
printf("Corrupted end of central directory locator offset : 0x%08" PRIX64 "\n", zip->locator.eocdOffset);
22222234
freeZip(zip);
22232235
return 0; /* FAILED */
22242236
}
@@ -2247,13 +2259,13 @@ static ZIP_FILE *openZip(const char *filename)
22472259
zip->centralDirectorySize = zip->eocdr.centralDirectorySize;
22482260
zip->centralDirectoryRecordCount = (uint64_t)zip->eocdr.totalEntries;
22492261
if (zip->centralDirectoryRecordCount > UINT16_MAX) {
2250-
printf("Corrupted total number of entries in the central directory : 0x%08lX\n", zip->centralDirectoryRecordCount);
2262+
printf("Corrupted total number of entries in the central directory : 0x%08" PRIX64 "\n", zip->centralDirectoryRecordCount);
22512263
freeZip(zip);
22522264
return NULL; /* FAILED */
22532265
}
22542266
}
22552267
if (zip->centralDirectoryOffset >= (uint64_t)zip->fileSize) {
2256-
printf("Corrupted central directory offset : 0x%08lX\n", zip->centralDirectoryOffset);
2268+
printf("Corrupted central directory offset : 0x%08" PRIX64 "\n", zip->centralDirectoryOffset);
22572269
freeZip(zip);
22582270
return NULL; /* FAILED */
22592271
}
@@ -2645,7 +2657,7 @@ static int readZip64EOCDR(ZIP64_EOCDR *eocdr, FILE *file, uint64_t offset)
26452657
/* zip64 extensible data sector (comment) */
26462658
eocdr->commentLen = eocdr->eocdrSize - 44;
26472659
if (eocdr->commentLen > UINT16_MAX) {
2648-
printf("Corrupted file comment length : 0x%08lX\n", eocdr->commentLen);
2660+
printf("Corrupted file comment length : 0x%08" PRIX64 "\n", eocdr->commentLen);
26492661
return 0; /* FAILED */
26502662
}
26512663
if (eocdr->commentLen > 0) {

script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ static SCRIPT_CTX *script_ctx_get(char *indata, uint32_t filesize, const SCRIPT_
680680
line_pos++; /* we can ignore lines longer than our buffer */
681681
}
682682
}
683-
printf("Signature position: %ld\n", sig_pos);
683+
printf("Signature position: %zu\n", sig_pos);
684684

685685
script_ctx = OPENSSL_malloc(sizeof(SCRIPT_CTX));
686686
script_ctx->comment_text = comment;

0 commit comments

Comments
 (0)