Skip to content

Commit

Permalink
Fix segmentation fault in setOauthbearerTokenRefreshCb when sasl.oaut…
Browse files Browse the repository at this point in the history
…hbearer.config is unset (#568)

Only call ZVAL_STRING for &args[1] with oauthbearer_config if oauthbearer_config is set in kafka_conf_set_oauthbearer_token_refresh_cb

Fixes #567
  • Loading branch information
scorgn authored Oct 31, 2024
1 parent 3cdcdf5 commit 9a93590
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ static void kafka_conf_set_oauthbearer_token_refresh_cb(rd_kafka_t *rk, const ch
ZVAL_NULL(&args[1]);

ZVAL_ZVAL(&args[0], &cbs->zrk, 1, 0);
ZVAL_STRING(&args[1], oauthbearer_config);

if (oauthbearer_config) {
ZVAL_STRING(&args[1], oauthbearer_config);
}

rdkafka_call_function(&cbs->oauthbearer_token_refresh->fci, &cbs->oauthbearer_token_refresh->fcc, NULL, 2, args);

Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<file role="test" name="bug465.phpt"/>
<file role="test" name="bug508.phpt"/>
<file role="test" name="bug521.phpt"/>
<file role="test" name="bug567.phpt"/>
<file role="test" name="bug74.phpt"/>
<file role="test" name="bug88.phpt"/>
<file role="test" name="bugConfSetArgument.phpt"/>
Expand Down
26 changes: 26 additions & 0 deletions tests/bug567.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Bug #567
--SKIPIF--
<?php
RD_KAFKA_VERSION >= 0x01010000 || die("skip librdkafka too old does not support oauthbearer");
--FILE--
<?php

$conf = new RdKafka\Conf();
if (RD_KAFKA_VERSION >= 0x090000 && false !== getenv('TEST_KAFKA_BROKER_VERSION')) {
$conf->set('broker.version.fallback', getenv('TEST_KAFKA_BROKER_VERSION'));
}

$conf->set('metadata.broker.list', 'foobar');
$conf->set('security.protocol', 'SASL_PLAINTEXT');
$conf->set('sasl.mechanisms', 'OAUTHBEARER');
$conf->setOauthbearerTokenRefreshCb(function ($producer) {
echo "oauthbearer token refresh callback successfully called\n";
});
$producer = new \RdKafka\Producer($conf);
$producer->poll(0);
echo "producer polled successfully\n";

--EXPECT--
oauthbearer token refresh callback successfully called
producer polled successfully

0 comments on commit 9a93590

Please sign in to comment.