Reported and tested by Thijs ([email protected]).
See also
http://sourceforge.net/tracker/?func=detail&atid=312694&aid=3067540&group_id=12694.
A quote from that patch tracker item:
We're currently working on a 64-bit port of our application, and found a bug
> in the code handling ip addresses on 64 bit architectures. The patch is
> rebased on the latest 5.6.rc2 code, but we found it in 5.3, so it might be
> worth while applying it in maintenance branches as well.
>
> First, the usage here is inconsistent with most other uses of IP addresses
> inside netsnmp, which are generally treated as strings of 4 bytes in network
> byte order.
>
> Second, the actual bug is that in build_oid_segment an ip address is
> accessed by dereferencing the integer part of the union netsnmp_vardata
> while the ip address has been written as a 4 byte value to the string part
> of the union. This results on 64 platforms in an 8 byte long value of which
> the lower 32bits of the integer part are subsequently accessed, resulting in
> a 0.0.0.0 ip address on big-endian machines.
>
Index: snmplib/mib.c
===================================================================
--- snmplib/mib.c (revision 19377)
+++ snmplib/mib.c (working copy)
@@ -3611,6 +3611,7 @@ int
build_oid_segment(netsnmp_variable_list * var)
{
int i;
+ uint32_t ipaddr;
if (var->name && var->name != var->name_loc)
SNMP_FREE(var->name);
@@ -3627,14 +3628,11 @@ build_oid_segment(netsnmp_variable_list
case ASN_IPADDRESS:
var->name_length = 4;
var->name = var->name_loc;
- var->name[0] =
- (((unsigned int) *(var->val.integer)) & 0xff000000) >> 24;
- var->name[1] =
- (((unsigned int) *(var->val.integer)) & 0x00ff0000) >> 16;
- var->name[2] =
- (((unsigned int) *(var->val.integer)) & 0x0000ff00) >> 8;
- var->name[3] =
- (((unsigned int) *(var->val.integer)) & 0x000000ff);
+ memcpy(&ipaddr, var->val.string, sizeof(ipaddr));
+ var->name[0] = (ipaddr >> 24) & 0xff;
+ var->name[1] = (ipaddr >> 16) & 0xff;
+ var->name[2] = (ipaddr >> 8) & 0xff;
+ var->name[3] = (ipaddr >> 0) & 0xff;
break;
case ASN_PRIV_IMPLIED_OBJECT_ID:
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders