mirror of
https://github.com/mtrojnar/osslsigncode.git
synced 2025-04-05 01:00:11 -05:00
Handled memory reallocation error
This commit is contained in:
parent
771014a41e
commit
3c8c74a8c3
29
msi.c
29
msi.c
@ -1499,15 +1499,20 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ministream_append(MSI_OUT *out, char *buf, uint32_t len)
|
static int ministream_append(MSI_OUT *out, char *buf, uint32_t len)
|
||||||
{
|
{
|
||||||
uint32_t needSectors = (len + out->sectorSize - 1) / out->sectorSize;
|
uint32_t needSectors = (len + out->sectorSize - 1) / out->sectorSize;
|
||||||
if (out->miniStreamLen + len >= (uint64_t)out->ministreamsMemallocCount * out->sectorSize) {
|
if (out->miniStreamLen + len >= (uint64_t)out->ministreamsMemallocCount * out->sectorSize) {
|
||||||
out->ministreamsMemallocCount += needSectors;
|
out->ministreamsMemallocCount += needSectors;
|
||||||
out->ministream = OPENSSL_realloc(out->ministream, (size_t)(out->ministreamsMemallocCount * out->sectorSize));
|
out->ministream = OPENSSL_realloc(out->ministream, (size_t)(out->ministreamsMemallocCount * out->sectorSize));
|
||||||
|
if (!out->ministream) {
|
||||||
|
printf("Memory allocation failure\n");
|
||||||
|
return 0; /* FAILED */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(out->ministream + out->miniStreamLen, buf, (size_t)len);
|
memcpy(out->ministream + out->miniStreamLen, buf, (size_t)len);
|
||||||
out->miniStreamLen += len;
|
out->miniStreamLen += len;
|
||||||
|
return 1; /* OK */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int minifat_append(MSI_OUT *out, char *buf, uint32_t len)
|
static int minifat_append(MSI_OUT *out, char *buf, uint32_t len)
|
||||||
@ -1519,6 +1524,10 @@ static int minifat_append(MSI_OUT *out, char *buf, uint32_t len)
|
|||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
}
|
}
|
||||||
out->minifat = OPENSSL_realloc(out->minifat, (size_t)(out->minifatMemallocCount * out->sectorSize));
|
out->minifat = OPENSSL_realloc(out->minifat, (size_t)(out->minifatMemallocCount * out->sectorSize));
|
||||||
|
if (!out->minifat) {
|
||||||
|
printf("Memory allocation failure\n");
|
||||||
|
return 0; /* FAILED */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(out->minifat + out->minifatLen, buf, (size_t)len);
|
memcpy(out->minifat + out->minifatLen, buf, (size_t)len);
|
||||||
out->minifatLen += len;
|
out->minifatLen += len;
|
||||||
@ -1534,6 +1543,10 @@ static int fat_append(MSI_OUT *out, char *buf, uint32_t len)
|
|||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
}
|
}
|
||||||
out->fat = OPENSSL_realloc(out->fat, (size_t)(out->fatMemallocCount * out->sectorSize));
|
out->fat = OPENSSL_realloc(out->fat, (size_t)(out->fatMemallocCount * out->sectorSize));
|
||||||
|
if (!out->fat) {
|
||||||
|
printf("Memory allocation failure\n");
|
||||||
|
return 0; /* FAILED */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(out->fat + out->fatLen, buf, (size_t)len);
|
memcpy(out->fat + out->fatLen, buf, (size_t)len);
|
||||||
out->fatLen += len;
|
out->fatLen += len;
|
||||||
@ -1549,6 +1562,10 @@ static int difat_append(MSI_OUT *out, char *buf, uint32_t len)
|
|||||||
return 0; /* FAILED */
|
return 0; /* FAILED */
|
||||||
}
|
}
|
||||||
out->difat = OPENSSL_realloc(out->difat, (size_t)(out->difatMemallocCount * out->sectorSize));
|
out->difat = OPENSSL_realloc(out->difat, (size_t)(out->difatMemallocCount * out->sectorSize));
|
||||||
|
if (!out->difat) {
|
||||||
|
printf("Memory allocation failure\n");
|
||||||
|
return 0; /* FAILED */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(out->difat + out->difatLen, buf, (size_t)len);
|
memcpy(out->difat + out->difatLen, buf, (size_t)len);
|
||||||
out->difatLen += len;
|
out->difatLen += len;
|
||||||
@ -1696,12 +1713,18 @@ static int stream_handle(MSI_FILE *msi, MSI_DIRENT *dirent, u_char *p_msi, uint3
|
|||||||
if (inlen < MINI_STREAM_CUTOFF_SIZE) {
|
if (inlen < MINI_STREAM_CUTOFF_SIZE) {
|
||||||
/* set the index into the mini FAT to track the chain of sectors through the mini stream */
|
/* set the index into the mini FAT to track the chain of sectors through the mini stream */
|
||||||
child->entry->startSectorLocation = out->miniSectorNum;
|
child->entry->startSectorLocation = out->miniSectorNum;
|
||||||
ministream_append(out, indata, inlen);
|
if (!ministream_append(out, indata, inlen)) {
|
||||||
|
OPENSSL_free(indata);
|
||||||
|
return 0; /* FAILED */
|
||||||
|
}
|
||||||
/* fill to the end with known data, such as all zeroes */
|
/* fill to the end with known data, such as all zeroes */
|
||||||
if (inlen % msi->m_minisectorSize > 0) {
|
if (inlen % msi->m_minisectorSize > 0) {
|
||||||
uint32_t remain = msi->m_minisectorSize - inlen % msi->m_minisectorSize;
|
uint32_t remain = msi->m_minisectorSize - inlen % msi->m_minisectorSize;
|
||||||
memset(buf, 0, (size_t)remain);
|
memset(buf, 0, (size_t)remain);
|
||||||
ministream_append(out, buf, remain);
|
if (!ministream_append(out, buf, remain)) {
|
||||||
|
OPENSSL_free(indata);
|
||||||
|
return 0; /* FAILED */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (inlen > msi->m_minisectorSize) {
|
while (inlen > msi->m_minisectorSize) {
|
||||||
out->miniSectorNum++;
|
out->miniSectorNum++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user