Skip to content

Commit 7b475cb

Browse files
committed
CID 909359: INTEGER_OVERFLOW
1 parent cff2a9a commit 7b475cb

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

  • minimal-examples-lowlevel/crypto/minimal-crypto-susvalid

minimal-examples-lowlevel/crypto/minimal-crypto-susvalid/main.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,26 @@ dump_context(struct parse_state *s)
7070
uint8_t temp[80];
7171
size_t i, start;
7272
size_t ahead = 0;
73+
size_t count = s->ring_count;
7374

74-
if (!s->ring_count)
75+
/* satisfy coverity constraint solver */
76+
if (count > 64)
77+
count = 64;
78+
79+
if (!count)
7580
return;
7681

77-
start = (s->ring_head + 64 - s->ring_count) % 64;
78-
for (i = 0; i < s->ring_count; i++)
82+
start = (s->ring_head + 64 - count) % 64;
83+
for (i = 0; i < count; i++)
7984
temp[i] = s->ring[(start + i) % 64];
8085

8186
if (s->fd >= 0) {
8287
off_t cur = lseek(s->fd, 0, SEEK_CUR);
8388
if (cur >= (off_t)0) {
8489
if (lseek(s->fd, (off_t)s->raw_byte_pos, SEEK_SET) != (off_t)-1) {
85-
ssize_t r = read(s->fd, temp + s->ring_count, 16);
86-
if (r > 0) {
90+
ssize_t r = read(s->fd, temp + count, 16);
91+
if (r > 0 && r <= 16) {
8792
ahead = (size_t)r;
88-
if (ahead > 16)
89-
ahead = 16;
9093
}
9194
}
9295
if (lseek(s->fd, cur, SEEK_SET) == (off_t)-1) {
@@ -95,7 +98,11 @@ dump_context(struct parse_state *s)
9598
}
9699
}
97100

98-
lwsl_hexdump_warn(temp, s->ring_count + ahead);
101+
/* satisfy coverity constraint solver */
102+
if (count + ahead > sizeof(temp))
103+
ahead = sizeof(temp) - count;
104+
105+
lwsl_hexdump_warn(temp, count + ahead);
99106
}
100107

101108
static void

0 commit comments

Comments
 (0)