Skip to content

Commit fd01627

Browse files
committed
coverity: silence CID 1691836 / 1691837
CID 1691837 (NULL_RETURNS) in rlm_kafka's kafka_xlat_produce(): Coverity doesn't trust the xlat framework's required=true contract and flags the downstream derefs of key_vb and value_vb. Add an fr_assert after the vars to document the invariant and silence it. CID 1691836 (RESOURCE_LEAK) in fr_atomic_ring_push(): Coverity doesn't track atomic stores as reference publication, so when we atomic_store_explicit() `n` into h->next and ring->head it still considers `n` leaked once the local goes out of scope. It isn't - the consumer frees it via atomic_ring_entry_free() once it advances past. Annotate with /* coverity[leaked_storage] */.
1 parent 6daacc9 commit fd01627

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/lib/io/atomic_queue.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,16 @@ bool fr_atomic_ring_push(fr_atomic_ring_t *ring, void *data)
569569
atomic_store_explicit(&h->next, n, memory_order_release);
570570
atomic_store_explicit(&ring->head, n, memory_order_relaxed);
571571

572+
/*
573+
* coverity[leaked_storage]
574+
*
575+
* Coverity doesn't track atomic stores as reference
576+
* publication, so it sees `n` going out of scope and
577+
* flags it as leaked. It isn't: the two atomic stores
578+
* above have published `n` into both `h->next` and
579+
* `ring->head`, and the consumer will free it via
580+
* atomic_ring_entry_free() once it advances past.
581+
*/
572582
return fr_atomic_queue_push(n->q, data);
573583
}
574584

src/modules/rlm_kafka/rlm_kafka.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,15 @@ static xlat_action_t kafka_xlat_produce(UNUSED TALLOC_CTX *xctx_ctx, UNUSED fr_d
790790
uint8_t const *key = NULL;
791791
size_t key_len = 0;
792792

793+
/*
794+
* The xlat framework enforces the arg contract before calling
795+
* us: `required = true` for topic + value, and the required
796+
* value slot after key keeps key's position filled even when
797+
* the caller passes `null`. Assert the invariant so Coverity
798+
* stops flagging the downstream derefs.
799+
*/
800+
fr_assert(topic_vb && key_vb && value_vb);
801+
793802
/*
794803
* Fast path: a literal topic argument was pre-resolved to
795804
* an rd_kafka_topic_t at xlat_instantiate time.

0 commit comments

Comments
 (0)