snmp.php : format_snmp_string() bug

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
gnu4lbator
Posts: 2
Joined: Fri Apr 18, 2008 10:10 am

snmp.php : format_snmp_string() bug

Post by gnu4lbator »

Hello,

I found a little bug in the function format_snmp_string in lib/snmp.php.

Code: Select all

$string = trim(ereg_replace(".*= ?", "", $string));
The regex does not match if the value contain a '='.

On some equipements, the SNMP ifAlias value contains the '=' character.

Code: Select all

Example : 
.1.3.6.1.2.1.31.1.1.1.18.109 = STRING: === SOME TEXT ===
So i changed the regex to :

Code: Select all

$string = trim(ereg_replace("^[^ ]* ?= ?", "", $string));
I don't know if this regex is bug free, but it work on all my equipement.

If you have a better regex, tell me.
Maybe you could change it in future versions.

cheers
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

That's indeed a good find. I fear that this has hit already some users. As an alternative, I suggest using

Code: Select all

$string = trim(substr($string, strpos($string, "=")+1));
which simply finds the first "=" and gets the rest of the string. It fails only, if an OID (be it ASN.1 or textual representation) contains a "=" which IMHO is not allowed by RFC.
Reinhard
gnu4lbator
Posts: 2
Joined: Fri Apr 18, 2008 10:10 am

Post by gnu4lbator »

Thanks for the idea, but there is a little mistake i think

$string = trim(substr($string, strpos($string, "=")+1)); doesn't work.
It strip the first character INTEGER become NTEGER ...

The working code is :

Code: Select all

$string = trim(substr($string, strpos($string, "=")));
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests