Skip to content

Commit f502e94

Browse files
ext/snmp: improve GH-21341 test: wider walk subtree, trailing-dot check
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent 729e45b commit f502e94

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

ext/snmp/tests/gh21341.phpt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ if (getenv('SKIP_ASAN')) die('skip Timeouts under ASAN');
1212
require_once(__DIR__.'/snmp_include.inc');
1313

1414
/* Exercise the suffix-as-keys code path (SNMP_USE_SUFFIX_AS_KEYS |
15-
* SNMP_CMD_WALK). The walk OID is chosen so the returned subidentifiers
16-
* form a multi-component suffix, driving multiple iterations of the
17-
* snprintf loop that GH-21341 replaced the strcat loop with. */
15+
* SNMP_CMD_WALK). Walking .1.3.6.1.2.1 (mib-2) returns entries whose
16+
* suffixes have multiple components (e.g. "1.1.0", "2.1.1.0"), driving
17+
* several iterations of the snprintf loop that GH-21341 replaced the
18+
* strcat loop with. */
1819
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
19-
$result = $session->walk('.1.3.6.1.2.1.1', /* suffix_as_keys */ true);
20+
$result = $session->walk('.1.3.6.1.2.1', /* suffix_as_keys */ true);
2021

2122
var_dump(is_array($result));
2223
var_dump(count($result) > 0);
@@ -28,10 +29,18 @@ $bad = array_filter(array_keys($result), static function (string $k): bool {
2829
});
2930
var_dump(count($bad) === 0);
3031

32+
/* No key may end with '.': the trailing-dot removal (buf2[pos-1] = '\0')
33+
* must fire correctly on every entry. */
34+
$trailing = array_filter(array_keys($result), static function (string $k): bool {
35+
return $k !== '' && $k[-1] === '.';
36+
});
37+
var_dump(count($trailing) === 0);
38+
3139
var_dump($session->close());
3240
?>
3341
--EXPECT--
3442
bool(true)
3543
bool(true)
3644
bool(true)
3745
bool(true)
46+
bool(true)

0 commit comments

Comments
 (0)