mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-22 07:58:22 +08:00
Fix potential bugs found with static analysis
This commit is contained in:
parent
2cbd78fb9e
commit
5edd5c10ee
@ -2399,7 +2399,10 @@ int i, c, v;
|
|||||||
v = (bl->qty - 1) * len;
|
v = (bl->qty - 1) * len;
|
||||||
if ((bl->qty > 512 || len > 127) &&
|
if ((bl->qty > 512 || len > 127) &&
|
||||||
v / len != bl->qty - 1) return NULL; /* Overflow */
|
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;
|
c += v;
|
||||||
p = b->data = (unsigned char *) bstr__alloc (c);
|
p = b->data = (unsigned char *) bstr__alloc (c);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
@ -2542,6 +2545,7 @@ int bssplitstrcb (struct bStream * s, const_bstring splitStr,
|
|||||||
}
|
}
|
||||||
buff->slen = 0;
|
buff->slen = 0;
|
||||||
}
|
}
|
||||||
|
bdestroy (buff);
|
||||||
return BSTR_OK;
|
return BSTR_OK;
|
||||||
} else {
|
} else {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -46,7 +46,9 @@ VOID uint32ToUint24(UINT32 size, UINT8* ffsSize)
|
|||||||
|
|
||||||
UINT32 uint24ToUint32(const 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)
|
UString guidToUString(const EFI_GUID & guid, bool convertToString)
|
||||||
|
@ -90,7 +90,7 @@ static const unsigned long K[64] = {
|
|||||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||||
#endif
|
#endif
|
||||||
/* compress 512-bits */
|
/* 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 S[8], W[64], t0, t1;
|
||||||
uint32_t t;
|
uint32_t t;
|
||||||
@ -122,7 +122,6 @@ h = t0 + t1;
|
|||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
md->state[i] = md->state[i] + S[i];
|
md->state[i] = md->state[i] + S[i];
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
/* Initialize the hash state */
|
/* Initialize the hash state */
|
||||||
void sha256_init(struct sha256_state *md)
|
void sha256_init(struct sha256_state *md)
|
||||||
@ -154,8 +153,7 @@ int sha256_process(struct sha256_state *md, const unsigned char *in,
|
|||||||
return -1;
|
return -1;
|
||||||
while (inlen > 0) {
|
while (inlen > 0) {
|
||||||
if (md->curlen == 0 && inlen >= block_size) {
|
if (md->curlen == 0 && inlen >= block_size) {
|
||||||
if (sha256_compress(md, (unsigned char *) in) < 0)
|
sha256_compress(md, (unsigned char *) in);
|
||||||
return -1;
|
|
||||||
md->length += block_size * 8;
|
md->length += block_size * 8;
|
||||||
in += block_size;
|
in += block_size;
|
||||||
inlen -= block_size;
|
inlen -= block_size;
|
||||||
@ -166,8 +164,7 @@ int sha256_process(struct sha256_state *md, const unsigned char *in,
|
|||||||
in += n;
|
in += n;
|
||||||
inlen -= n;
|
inlen -= n;
|
||||||
if (md->curlen == block_size) {
|
if (md->curlen == block_size) {
|
||||||
if (sha256_compress(md, md->buf) < 0)
|
sha256_compress(md, md->buf);
|
||||||
return -1;
|
|
||||||
md->length += 8 * block_size;
|
md->length += 8 * block_size;
|
||||||
md->curlen = 0;
|
md->curlen = 0;
|
||||||
}
|
}
|
||||||
|
@ -190,8 +190,11 @@ local const config configuration_table[10] = {
|
|||||||
* prev[] will be initialized on the fly.
|
* prev[] will be initialized on the fly.
|
||||||
*/
|
*/
|
||||||
#define CLEAR_HASH(s) \
|
#define CLEAR_HASH(s) \
|
||||||
s->head[s->hash_size-1] = NIL; \
|
do { \
|
||||||
zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
|
s->head[s->hash_size-1] = NIL; \
|
||||||
|
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
|
* Slide the hash table when sliding the window down (could be avoided with 32
|
||||||
|
Loading…
Reference in New Issue
Block a user