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