Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ip address with length 0 #53

Closed
benjamin-thomas opened this issue Jul 10, 2015 · 4 comments
Closed

ip address with length 0 #53

benjamin-thomas opened this issue Jul 10, 2015 · 4 comments

Comments

@benjamin-thomas
Copy link
Contributor

I've run into devices returning a 0 length ip addresses, mainly Lexmark printers (for example Lexmark CX310dn)

This line returns the following error in my program:

Error decoding value: got ipaddress len 0, expected 4 or 16

For the moment, I've been ignoring/skipping this error in my own program, but was wondering if there would be any drawbacks or objections to initialize an "empty" ip address (for example 0.0.0.0 or nil) and not return an error instead?

Any thoughts?

@ctrlrsf
Copy link
Contributor

ctrlrsf commented Jul 10, 2015

@benjamin-thomas What does a net-snmp tool such as snmpwalk or snmpget show for that OID?

@benjamin-thomas
Copy link
Contributor Author

Here is the relevant snmpwalk output (the problematic OID is .1.3.6.1.4.1.641.1.9.8.0)

.1.3.6.1.4.1.641.1.9.4.0 = INTEGER: 2
.1.3.6.1.4.1.641.1.9.5.0 = STRING: "5003020000"
.1.3.6.1.4.1.641.1.9.6.0 = STRING: "5010030000"
.1.3.6.1.4.1.641.1.9.7.0 = INTEGER: 60
.1.3.6.1.4.1.641.1.9.8.0 = IpAddress: 60.0.0.0
.1.3.6.1.4.1.641.1.9.9.0 = ""
.1.3.6.1.4.1.641.2.1.1.0 = INTEGER: 1
.1.3.6.1.4.1.641.2.1.2.1.1.1 = INTEGER: 1
.1.3.6.1.4.1.641.2.1.2.1.2.1 = STRING: "Lexmark CX310dn"
.1.3.6.1.4.1.641.2.1.2.1.3.1 = STRING: "MANUFACTURER:Lexmark International;COMMAND SET:;MODEL:Lexmark CX310dn"
.1.3.6.1.4.1.641.2.1.2.1.4.1 = STRING: "LW20.GM2.P231-0"

Here is the output of my program with debug output (the retry messages are my own, the rest is the library's debug output)

OID: .1.3.6.1.4.1.641.1.9.8.0
decodeValue: value
0   40 00 
decodeValue: type is IPAddress
Retry number 1. Last error was: Unable to decode packet: Error in unmarshalResponse: Error decoding value: got ipaddress len 0, expected 4 or 16
Packet sanity verified, we got all the bytes (46)
parseRawField: version
0   02 01 00 04 06 70 75 62
8   6c 69 63 a2 1f 02 04 34
Parsed version 0
parseRawField: community
0   04 06 70 75 62 6c 69 63
8   a2 1f 02 04 34 3c 02 91
Parsed community public
SNMP Packet is GET RESPONSE
0   a2 1f 02 04 34 3c 02 91
8   02 01 00 02 01 00 30 11
getResponseLength: 33
parseRawField: request id
0   02 04 34 3c 02 91 02 01
8   00 02 01 00 30 11 30 0f
requestID: 876348049
parseRawField: error-status
0   02 01 00 02 01 00 30 11
8   30 0f 06 0b 2b 06 01 04
errorStatus: 0
parseRawField: error index
0   02 01 00 30 11 30 0f 06
8   0b 2b 06 01 04 01 85 01
error-index: 0

=== unmarshalVBL()
0   30 11 30 0f 06 0b 2b 06
8   01 04 01 85 01 01 09 08
16  30 11 30 
vblLength: 19

STARTING a varbind. Cursor 2
0   30 0f 06 0b 2b 06 01 04
8   01 85 01 01 09 08 00 40
16  30 
parseRawField: OID
0   06 0b 2b 06 01 04 01 85
8   06 0b 2b 06 01 04 01 
OID: .1.3.6.1.4.1.641.1.9.8.0
decodeValue: value
0   40 00 
decodeValue: type is IPAddress
Retry number 2. Last error was: Unable to decode packet: Error in unmarshalResponse: Error decoding value: got ipaddress len 0, expected 4 or 16

I had to scan the .1.3.6.1.4 "branch" separately with snmpwalk.

When starting to scan from .1.3.6, the last returned oid was .1.3.6.1.2.1.55.1.8.1.5.8.

My guess is snmpwalk crashed because of bad data.

I'm not sure how to interpret the raw data though.

@codedance
Copy link
Contributor

From memory I added the IP parsing code... never expecting that an IP address could be of length zero according to ASN.1/BER. The real world always has different ideas :-) We should make our library as resilient at possible and I think we should code around this to support "the real world".

I can see two options:

Option 1)
Initialised to nil (not 0.0.0.0) I think returning 0.0.0.0 would be wrong as this as has different meaning. You can test for a nil value your up stream code.

Option 2)
Another option would be to say it's "bad data" and just remap the type as the Null type (0x05)

retVal.Type = Null
retVal.Value = nil

I'd welcome some thoughts/votes?

@mgenov
Copy link
Contributor

mgenov commented Sep 26, 2015

+1 for Option 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants