Skip to content

Commit 9a93590

Browse files
authored
Fix segmentation fault in setOauthbearerTokenRefreshCb when sasl.oauthbearer.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
1 parent 3cdcdf5 commit 9a93590

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

conf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ static void kafka_conf_set_oauthbearer_token_refresh_cb(rd_kafka_t *rk, const ch
365365
ZVAL_NULL(&args[1]);
366366

367367
ZVAL_ZVAL(&args[0], &cbs->zrk, 1, 0);
368-
ZVAL_STRING(&args[1], oauthbearer_config);
368+
369+
if (oauthbearer_config) {
370+
ZVAL_STRING(&args[1], oauthbearer_config);
371+
}
369372

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

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
<file role="test" name="bug465.phpt"/>
119119
<file role="test" name="bug508.phpt"/>
120120
<file role="test" name="bug521.phpt"/>
121+
<file role="test" name="bug567.phpt"/>
121122
<file role="test" name="bug74.phpt"/>
122123
<file role="test" name="bug88.phpt"/>
123124
<file role="test" name="bugConfSetArgument.phpt"/>

tests/bug567.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #567
3+
--SKIPIF--
4+
<?php
5+
RD_KAFKA_VERSION >= 0x01010000 || die("skip librdkafka too old does not support oauthbearer");
6+
--FILE--
7+
<?php
8+
9+
$conf = new RdKafka\Conf();
10+
if (RD_KAFKA_VERSION >= 0x090000 && false !== getenv('TEST_KAFKA_BROKER_VERSION')) {
11+
$conf->set('broker.version.fallback', getenv('TEST_KAFKA_BROKER_VERSION'));
12+
}
13+
14+
$conf->set('metadata.broker.list', 'foobar');
15+
$conf->set('security.protocol', 'SASL_PLAINTEXT');
16+
$conf->set('sasl.mechanisms', 'OAUTHBEARER');
17+
$conf->setOauthbearerTokenRefreshCb(function ($producer) {
18+
echo "oauthbearer token refresh callback successfully called\n";
19+
});
20+
$producer = new \RdKafka\Producer($conf);
21+
$producer->poll(0);
22+
echo "producer polled successfully\n";
23+
24+
--EXPECT--
25+
oauthbearer token refresh callback successfully called
26+
producer polled successfully

0 commit comments

Comments
 (0)