oss-fuzz: Fix undefined-behavior

Analyzer run time does not like A -= B or A +=B even if A and B are uint32_t as there is potential
for overflow.

Analyzer run time does not like overflow when doing coap_tick_t - coap_tick_t.

Analyzer run time does not like (uint8_t << 24) as uint8_t is promoted as int, not u_int.

Analyzer run time does not like while(A--) {} even if A is uint32_t, as A is always decremented on
the test, even if the value of A is 0.

Fix potential overflow when analyzing an asn.1 tag.

Fix potential overflow when doing decode_segment() on a % hex value.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2026-03-10 11:09:10 +00:00
1 parent fe41b51aab
commit 40502ffebb
9 files changed
+44 -37

No files matched your search

+4 -3
View File
@@ -36,7 +36,8 @@ coap_queue_t *node[5];
static coap_tick_t
add_timestamps(coap_queue_t *queue, size_t num) {
coap_tick_t t = 0;
while (queue && num--) {
while (queue && num) {
num--;
t += queue->t;
queue = queue->next;
}
@@ -133,7 +134,7 @@ t_sendqueue5(void) {
coap_ticks(&now);
ctx->sendqueue_basetime = now;
now -= delta1;
now = (coap_tick_diff_t)now - (coap_tick_diff_t)delta1;
result = coap_adjust_basetime(ctx, now);
CU_ASSERT(result == 0);
@@ -141,7 +142,7 @@ t_sendqueue5(void) {
CU_ASSERT(ctx->sendqueue_basetime == now);
CU_ASSERT(ctx->sendqueue->t == timestamp[3] + delta1);
now += delta2;
now = (coap_tick_diff_t)now + (coap_tick_diff_t)delta2;
result = coap_adjust_basetime(ctx, now);
CU_ASSERT(result == 2);
CU_ASSERT(ctx->sendqueue_basetime == now);