Skip to content

Commit f703d01

Browse files
authored
assignor: fix rd_list destroy callback type mismatch (#5195) (#5278)
* assignor: fix rd_list destroy callback type mismatch (#5195) Fix the UBSan warning: runtime error: call to function rd_kafka_assignor_destroy through pointer to incorrect function type 'void (*)(void *)' by changing rd_kafka_assignor_destroy to take a void * argument, as expected by rd_list_init() destroy callbacks, and casting internally to rd_kafka_assignor_t *. Removed explicit cast from rd_list_init argument rd_kafka_assignor_destroy as it is exactly the type as expected by rd_list_init. * assignor: fix rd_list destroy callback type mismatch (#5195) Fix the UBSan warning: runtime error: call to function rd_kafka_assignor_destroy through pointer to incorrect function type 'void (*)(void *)' by adding two callback functions which are of required type and which call destroy callbacks internally. rd_list_init uses these new callbacks. 1. rd_kafka_assignor_topic_free(void *ptr) - calls rd_kafka_assignor_topic_destroy after typecasting ptr 2. rd_kafka_assignor_free(void *ptr) - calls rd_kafka_assignor_destroy after typecasting ptr These new callbacks are used in rd_list_init calls which are of expected types. These wrappers avoid the function type mismatch reported by UBSan while keeping the original destroy helpers typed to their concrete pointer types. This fixes the UBSan warning about calling the destroy callbacks through pointers with the wrong function type and removes the explicit casts at the rd_list_init() call sites. Tests: - UBSan enabled locally to reproduce and verify the issue - make quick on trivup (./interactive_broker_version.py 3.6.0)
1 parent 59b2f66 commit f703d01

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/rdkafka_assignor.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ static void rd_kafka_assignor_topic_destroy(rd_kafka_assignor_topic_t *at) {
240240
rd_free(at);
241241
}
242242

243+
/**
244+
* @brief Destroy-variant suitable for rd_list free_cb use.
245+
*/
246+
static void rd_kafka_assignor_topic_free(void *ptr) {
247+
rd_kafka_assignor_topic_destroy((rd_kafka_assignor_topic_t *)ptr);
248+
}
249+
243250
int rd_kafka_assignor_topic_cmp(const void *_a, const void *_b) {
244251
const rd_kafka_assignor_topic_t *a =
245252
*(const rd_kafka_assignor_topic_t *const *)_a;
@@ -267,7 +274,7 @@ rd_kafka_member_subscriptions_map(rd_kafka_cgrp_t *rkcg,
267274
rd_kafka_metadata_get_internal(metadata);
268275

269276
rd_list_init(eligible_topics, RD_MIN(metadata->topic_cnt, 10),
270-
(void *)rd_kafka_assignor_topic_destroy);
277+
rd_kafka_assignor_topic_free);
271278

272279
/* For each topic in the cluster, scan through the member list
273280
* to find matching subscriptions. */
@@ -457,6 +464,13 @@ static void rd_kafka_assignor_destroy(rd_kafka_assignor_t *rkas) {
457464
rd_free(rkas);
458465
}
459466

467+
/**
468+
* @brief Destroy-variant suitable for rd_list free_cb use.
469+
*/
470+
static void rd_kafka_assignor_free(void *ptr) {
471+
rd_kafka_assignor_destroy((rd_kafka_assignor_t *)ptr);
472+
}
473+
460474

461475
/**
462476
* @brief Check that the rebalance protocol of all enabled assignors is
@@ -580,7 +594,7 @@ int rd_kafka_assignors_init(rd_kafka_t *rk, char *errstr, size_t errstr_size) {
580594
int idx = 0;
581595

582596
rd_list_init(&rk->rk_conf.partition_assignors, 3,
583-
(void *)rd_kafka_assignor_destroy);
597+
rd_kafka_assignor_free);
584598

585599
/* Initialize builtin assignors (ignore errors) */
586600
rd_kafka_range_assignor_init(rk);

0 commit comments

Comments
 (0)