Fix potential bugs found with static analysis

This commit is contained in:
vit9696 2019-03-26 14:22:51 +03:00
parent 2cbd78fb9e
commit 5edd5c10ee
4 changed files with 16 additions and 10 deletions

View File

@ -2399,7 +2399,10 @@ int i, c, v;
v = (bl->qty - 1) * len;
if ((bl->qty > 512 || len > 127) &&
v / len != bl->qty - 1) return NULL; /* Overflow */
if (v > INT_MAX - c) return NULL; /* Overflow */
if (v > INT_MAX - c) {
bstr__free (b);
return NULL; /* Overflow */
}
c += v;
p = b->data = (unsigned char *) bstr__alloc (c);
if (p == NULL) {
@ -2542,6 +2545,7 @@ int bssplitstrcb (struct bStream * s, const_bstring splitStr,
}
buff->slen = 0;
}
bdestroy (buff);
return BSTR_OK;
} else {
for (;;) {

View File

@ -46,7 +46,9 @@ VOID uint32ToUint24(UINT32 size, UINT8* ffsSize)
UINT32 uint24ToUint32(const UINT8* ffsSize)
{
return readUnaligned((UINT32*)ffsSize) & 0x00FFFFFF;
return (UINT32) ffsSize[0]
+ ((UINT32) ffsSize[1] << 8U)
+ ((UINT32) ffsSize[2] << 16U);
}
UString guidToUString(const EFI_GUID & guid, bool convertToString)

View File

@ -90,7 +90,7 @@ static const unsigned long K[64] = {
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
/* compress 512-bits */
static int sha256_compress(struct sha256_state *md, unsigned char *buf)
static void sha256_compress(struct sha256_state *md, unsigned char *buf)
{
uint32_t S[8], W[64], t0, t1;
uint32_t t;
@ -122,7 +122,6 @@ h = t0 + t1;
for (i = 0; i < 8; i++) {
md->state[i] = md->state[i] + S[i];
}
return 0;
}
/* Initialize the hash state */
void sha256_init(struct sha256_state *md)
@ -154,8 +153,7 @@ int sha256_process(struct sha256_state *md, const unsigned char *in,
return -1;
while (inlen > 0) {
if (md->curlen == 0 && inlen >= block_size) {
if (sha256_compress(md, (unsigned char *) in) < 0)
return -1;
sha256_compress(md, (unsigned char *) in);
md->length += block_size * 8;
in += block_size;
inlen -= block_size;
@ -166,8 +164,7 @@ int sha256_process(struct sha256_state *md, const unsigned char *in,
in += n;
inlen -= n;
if (md->curlen == block_size) {
if (sha256_compress(md, md->buf) < 0)
return -1;
sha256_compress(md, md->buf);
md->length += 8 * block_size;
md->curlen = 0;
}

View File

@ -190,8 +190,11 @@ local const config configuration_table[10] = {
* prev[] will be initialized on the fly.
*/
#define CLEAR_HASH(s) \
do { \
s->head[s->hash_size-1] = NIL; \
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
zmemzero((Bytef *)s->head, \
(unsigned)(s->hash_size-1)*sizeof(*s->head)); \
} while (0)
/* ===========================================================================
* Slide the hash table when sliding the window down (could be avoided with 32