xref: /php-src/ext/snmp/tests/gh16959.phpt (revision becf207d)
1--TEST--
2snmpget() modifies object_id array source
3--EXTENSIONS--
4snmp
5--SKIPIF--
6<?php
7require_once(__DIR__.'/skipif.inc');
8if (getenv('SKIP_ASAN')) die('skip Causes timeout on asan');
9?>
10--FILE--
11<?php
12require_once(__DIR__.'/snmp_include.inc');
13
14$bad_object_ids = array (
15077 => 077, -066 => -066, -0345 => -0345, 0 => 0
16);
17var_dump($bad_object_ids);
18var_dump(snmpget($hostname, "", $bad_object_ids) === false);
19// The array should remain unmodified
20var_dump($bad_object_ids);
21try {
22	snmpget($hostname, "", [0 => new stdClass()]);
23} catch (Throwable $e) {
24	echo $e->getMessage() . PHP_EOL;
25}
26
27try {
28	snmp2_set($hostname, $communityWrite, $bad_object_ids, array(new stdClass()), array(null));
29} catch (Throwable $e) {
30	echo $e->getMessage() . PHP_EOL;
31}
32try {
33	snmp2_set($hostname, $communityWrite, $bad_object_ids, array("toolongtype"), array(null));
34} catch (Throwable $e) {
35	echo $e->getMessage() . PHP_EOL;
36}
37try {
38	snmp2_set($hostname, $communityWrite, $bad_object_ids, array(str_repeat("onetoomuch", random_int(1, 1))), array(null));
39} catch (Throwable $e) {
40	echo $e->getMessage();
41}
42?>
43--EXPECTF--
44array(4) {
45  [63]=>
46  int(63)
47  [-54]=>
48  int(-54)
49  [-229]=>
50  int(-229)
51  [0]=>
52  int(0)
53}
54
55Warning: snmpget(): Invalid object identifier: -54 in %s on line %d
56bool(true)
57array(4) {
58  [63]=>
59  int(63)
60  [-54]=>
61  int(-54)
62  [-229]=>
63  int(-229)
64  [0]=>
65  int(0)
66}
67Object of class stdClass could not be converted to string
68Object of class stdClass could not be converted to string
69Type must be a single character
70Type must be a single character
71