php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48273 [PATCH] snmp*_real_walk() returns SNMP errors as values
Submitted: 2009-05-14 06:46 UTC Modified: 2009-06-01 13:11 UTC
From: lytboris at gmail dot com Assigned:
Status: Closed Package: SNMP related
PHP Version: 5.2.9 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lytboris at gmail dot com
New email:
PHP Version: OS:

 

 [2009-05-14 06:46 UTC] lytboris at gmail dot com
Description:
------------
When remote SNMP agent returns an error with same OID that contained correct value *_real_walk functions will overwrite this correct value with error message because there is no snmp reply status check.

Here is patch to address this issue:
========
--- ext/snmp/snmp.c.orig        2008-12-31 14:17:43.000000000 +0300
+++ ext/snmp/snmp.c     2009-05-14 10:31:23.000000000 +0400
@@ -480,12 +480,15 @@
                                        } else if (st == SNMP_CMD_WALK) {
                                                add_next_index_zval(return_value,snmpval); /* Add to returned array */
                                        } else if (st == SNMP_CMD_REALWALK)  {
+                                               if (vars->type != SNMP_ENDOFMIBVIEW &&
+                                                       vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) {
 #ifdef HAVE_NET_SNMP
-                                               snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
+                                                       snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
 #else
-                                               sprint_objid(buf2, vars->name, vars->name_length);
+                                                       sprint_objid(buf2, vars->name, vars->name_length);
 #endif
-                                               add_assoc_zval(return_value,buf2,snmpval);
+                                                       add_assoc_zval(return_value,buf2,snmpval);
+                                               }
                                        }
                                        if (st >= SNMP_CMD_WALK && st != SNMP_CMD_SET) {
                                                if (vars->type != SNMP_ENDOFMIBVIEW &&
============

in BASE64 form:
begin-base64 644 -
LS0tIGV4dC9zbm1wL3NubXAuYy5vcmlnCTIwMDgtMTItMzEgMTQ6MTc6ND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yZXR1cm5fdmFs
dWUsYnVmMixzbm1wdmFsKTsKKwkJCQkJCX0KIAkJCQkJfQogCQkJCQlpZiAoc3QgPj0gU05NUF9D
TURfV0FMSyAmJiBzdCAhPSBTTk1QX0NNRF9TRVQpIHsKIAkJCQkJCWlmICh2YXJzLT50eXBlICE9
IFNOTVBfRU5ET0ZNSUJWSUVXICYmIAo=
====


Reproduce code:
---------------
print_r(@snmp2_real_walk("host:161", "community", ".1.3.6.1.4.1.8072.2.1.2.3", (800 * 1000), 2)):
=======
Result shown by snmpwalk:
>snmpwalk -v2c -ccommunity host .1.3.6.1.4.1.8072.2.1.2.3
NET-SNMP-MIB::netSnmp.2.1.2.3.1 = ""
NET-SNMP-MIB::netSnmp.2.1.2.3.2 = ""
NET-SNMP-MIB::netSnmp.2.1.2.3.3 = ""
NET-SNMP-MIB::netSnmp.2.1.2.3.4 = ""
NET-SNMP-MIB::netSnmp.2.1.2.3.5 = ""
NET-SNMP-MIB::netSnmp.2.1.2.3.6 = ""
NET-SNMP-MIB::netSnmp.2.1.2.3.7 = ""
NET-SNMP-MIB::netSnmp.2.1.2.3.8 = STRING: "blah"
NET-SNMP-MIB::netSnmp.2.1.2.3.8 = No more variables left in this MIB View (It is past the end of the MIB tree)


Expected result:
----------------
Array
(
    [NET-SNMP-MIB::netSnmp.2.1.2.3.1] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.2] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.3] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.4] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.5] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.6] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.7] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.8] => "blah"
)

Actual result:
--------------
Array
(
    [NET-SNMP-MIB::netSnmp.2.1.2.3.1] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.2] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.3] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.4] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.5] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.6] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.7] => ""
    [NET-SNMP-MIB::netSnmp.2.1.2.3.8] => No Such Instance currently exists at this OID
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-14 06:53 UTC] lytboris at gmail dot com
Oups,
last line in Actual result should be read as 
    [NET-SNMP-MIB::netSnmp.2.1.2.3.8] => No more variables left in this MIB
View (It is past the end of the MIB tree)


(wrong copy-paste)
 [2009-06-01 13:11 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC