Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
For bugs related to Red Hat Enterprise Linux 4 product line. The current stable release is 4.9. For Red Hat Enterprise Linux 6 and above, please visit Red Hat JIRA https://issues.redhat.com/secure/CreateIssue!default.jspa?pid=12332745 to report new issues.

Bug 464764

Summary: [RHEL4] IP address length is 8 bytes on 64bits
Product: Red Hat Enterprise Linux 4 Reporter: Olivier Fourdan <ofourdan>
Component: net-snmpAssignee: Jan Safranek <jsafrane>
Status: CLOSED ERRATA QA Contact: BaseOS QE <qe-baseos-auto>
Severity: high Docs Contact:
Priority: urgent    
Version: 4.6CC: jplans, kem, mkoci, nmurray, raghavendra_biligiri, rvokal, tao, wwlinuxengineering
Target Milestone: rcKeywords: ZStream
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard: GSSApproved
Fixed In Version: Doc Type: Bug Fix
Doc Text:
* the snmpd daemon reported IP address values with an incorrect length of 8 bytes on 64-bit architectures. This has been corrected by asserting within the snmp_client that an IP address has a length of 4 bytes.
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-05-18 20:18:23 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 466216    
Attachments:
Description Flags
Patch to fix the size of IP addresses on RHEL4
none
Much less intrusive and simpler patch none

Description Olivier Fourdan 2008-09-30 11:47:20 UTC
Created attachment 318061 [details]
Patch to fix the size of IP addresses on RHEL4

Description of problem:

IP address length is 8 bytes on 64bits

Version-Release number of selected component (if applicable):

net-snmp-5.1.2-13.el4.src.rpm

How reproducible:

100% reproducible on 64bits system where sizeof(long) is 8

Steps to Reproduce:
1. Install net-snmp-5.1.2-13
2. Make sure you can access the subtree 1.3.6.1.2.1.4.20.1.1
   allow view systemview included .1.3.6.1.2.1.4.20.1.1
3. snmpwalk -d -v1 -c public localhost 1.3.6.1.2.1.4.20.1.1
  
Actual results:

The address is 8 bytes long:

Received 56 bytes from 127.0.0.1
0000: 30 36 02 01  00 04 06 70  75 62 6C 69  63 A2 29 02    06.....public.).
0016: 04 76 A7 42  90 02 01 00  02 01 00 30  1B 30 19 06    .v.B.......0.0..
0032: 0D 2B 06 01  02 01 04 14  01 01 7F 00  00 01 40 08    .+............@.
0048: 7F 00 00 01  00 00 00 00                     ^^^^^    ........
      ^^^^^^^^^^^  ^^^^^^^^^^^
IP-MIB::ipAdEntAddr.127.0.0.1 = IpAddress: 127.0.0.1

Received 59 bytes from 127.0.0.1
0000: 30 39 02 01  00 04 06 70  75 62 6C 69  63 A2 2C 02    09.....public.,.
0016: 04 76 A7 42  91 02 01 00  02 01 00 30  1E 30 1C 06    .v.B.......0.0..
0032: 10 2B 06 01  02 01 04 14  01 01 81 2C  10 81 6F 81    .+.........,..o.
0048: 08 40 08 AC  10 EF 88 00  00 00 00                    .@.........
         ^^^^^^^^  ^^^^^^^^^^^  ^^^^^^^^
IP-MIB::ipAdEntAddr.172.16.239.136 = IpAddress: 172.16.239.136

Expected results:

The address is 4bytes long:

Received 52 bytes from 127.0.0.1
0000: 30 32 02 01  00 04 06 70  75 62 6C 69  63 A2 25 02    02.....public.%.
0016: 04 03 A3 63  5F 02 01 00  02 01 00 30  17 30 15 06    ...c_......0.0..
0032: 0D 2B 06 01  02 01 04 14  01 01 7F 00  00 01 40 04    .+............@.
0048: 7F 00 00 01                                  ^^^^^    ....
      ^^^^^^^^^^^
IP-MIB::ipAdEntAddr.127.0.0.1 = IpAddress: 127.0.0.1

Received 55 bytes from 127.0.0.1
0000: 30 35 02 01  00 04 06 70  75 62 6C 69  63 A2 28 02    05.....public.(.
0016: 04 03 A3 63  60 02 01 00  02 01 00 30  1A 30 18 06    ...c`......0.0..
0032: 10 2B 06 01  02 01 04 14  01 01 81 2C  10 81 6F 81    .+.........,..o.
0048: 08 40 04 AC  10 EF 88                                 .@.....
         ^^^^^^^^  ^^^^^^^^
         
IP-MIB::ipAdEntAddr.172.16.239.136 = IpAddress: 172.16.239.136

Additional info:

RFC-2962 http://www.ietf.org/rfc/rfc2962.txt gives:

    The last 6 bytes 40 04 87 B4 8C CA represent an IpAddress: 40 is
    the identification of the base type IpAddress, 04 is the length, and the
    next four bytes are the IP address value (135.180.140.202).

This bug was also reported on RHEL5 here:

    https://bugzilla.redhat.com/show_bug.cgi?id=253880

the patch that fixed the issue is different fro mthe one atatched to the BZ and actually called "/net-snmp-5.3.1-ip-size.patch".

However, backporting this patch to net-snmp-5.1.2 is not sufficient because the length is wrongly set to 8 bytes in snmp_set_var_value() (snmplib/snmp_client.c) where the size is reset to sizeof(long) even for ASN_IPADDRESS.

The patch attached fixes the issue by:

1) Backporting the fix from RHEL5 for net-snmp-5.3.1
2) Fixing snmp_set_var_value() to leave the size of 4 bytes for ASN_IPADDRESS based on the code from 5.3/upstream.
   http://net-snmp.svn.sourceforge.net/viewvc/net-snmp/trunk/net-snmp/snmplib/snmp_client.c?view=markup

Comment 1 Olivier Fourdan 2008-10-06 09:54:14 UTC
This is actually a regression in net-snmp on RHEL4.7 

net-snmp-5.1.2-11.x86_64.rpm:

    # snmpwalk -d -v1 -c public localhost 1.3.6.1.2.1.4.20.1.1

    Received 52 bytes from 127.0.0.1
    0000: 30 32 02 01  00 04 06 70  75 62 6C 69  63 A2 25 02    02.....public.%.
    0016: 04 3D 2D 40  09 02 01 00  02 01 00 30  17 30 15 06    .=-@.......0.0..
    0032: 0D 2B 06 01  02 01 04 14  01 01 7F 00  00 01 40 04    .+............@.
    0048: 7F 00 00 01                                  ^^^^^    ....
          ^^^^^^^^^^^

==> Ok

net-snmp-5.1.2-11.EL4.6.x86_64.rpm:

    # snmpwalk -d -v1 -c public localhost 1.3.6.1.2.1.4.20.1.1

    Received 52 bytes from 127.0.0.1
    0000: 30 32 02 01  00 04 06 70  75 62 6C 69  63 A2 25 02    02.....public.%.
    0016: 04 47 19 15  53 02 01 00  02 01 00 30  17 30 15 06    .G..S......0.0..
    0032: 0D 2B 06 01  02 01 04 14  01 01 7F 00  00 01 40 04    .+............@.
    0048: 7F 00 00 01                                  ^^^^^    ....
          ^^^^^^^^^^^
      
==> Ok

So this is indeed a regression that was introduced in 4.7.

The regression was sactually introduced by this patch in RHEL4.7:

    net-snmp-5.1.2-int-sizes.patch

Which introduced this:

    +    switch (vars->type) {
    +    case ASN_INTEGER:
    +    case ASN_UNSIGNED:
    +    case ASN_TIMETICKS:
    +    case ASN_IPADDRESS:
    +    case ASN_COUNTER:
    +        if (value) {
    +            if (largeval) {
    +                snmp_log(LOG_ERR,"bad size for integer-like type (%d)\n",
    +                         vars->val_len);
    +                return (1);
    +            } else if (vars->val_len == sizeof(int)) {
    +                if (ASN_INTEGER == vars->type) {
    +                    val_int = (const int *) value;
    +                    *(vars->val.integer) = (long) *val_int;
    +                } else {
    +                    val_uint = (const u_int *) value;
    +                    *(vars->val.integer) = (long) *val_uint;
    +                }
    +            } else {
    +                val_long = (const long *) value;
    +                *(vars->val.integer) = *val_long;
    +            }
             }
    -        memmove(newvar->val.string, val_str, val_len);
    -        newvar->val_len = val_len;
    -    } else if (val_str) {
    +        vars->val_len = sizeof(long);
    +        break;
    +

So actually, that part of the patch should suffice to fix the issue:

    --- net-snmp-5.1.2/snmplib/snmp_client.c.ip-size        2008-09-30 11:06:42.000000000 +0100
    +++ net-snmp-5.1.2/snmplib/snmp_client.c        2008-09-30 11:07:25.000000000 +0100
    @@ -752,7 +752,6 @@ snmp_set_var_value(netsnmp_variable_list
         case ASN_INTEGER:
         case ASN_UNSIGNED:
         case ASN_TIMETICKS:
    -    case ASN_IPADDRESS:
         case ASN_COUNTER:
             if (value) {
                 if (largeval) {
    @@ -789,6 +788,11 @@ snmp_set_var_value(netsnmp_variable_list
             memmove(vars->val.objid, value, vars->val_len);
             break;
     
    +    case ASN_IPADDRESS: /* snmp_build_var_op treats IPADDR like a string */
    +        if (4 != vars->val_len) {
    +            netsnmp_assert("ipaddress length == 4");
    +        }
    +        /** FALL THROUGH */
         case ASN_PRIV_IMPLIED_OCTET_STR:
         case ASN_OCTET_STR:
         case ASN_BIT_STR:

Example

    # snmpwalk -d -v1 -c public localhost 1.3.6.1.2.1.4.20.1.1
    [...]

    Received 52 bytes from 127.0.0.1
    0000: 30 32 02 01  00 04 06 70  75 62 6C 69  63 A2 25 02    02.....public.%.
    0016: 04 11 98 0D  C9 02 01 00  02 01 00 30  17 30 15 06    ...........0.0..
    0032: 0D 2B 06 01  02 01 04 14  01 01 7F 00  00 01 40 04    .+............@.
    0048: 7F 00 00 01                                  ^^^^^    ....
          ^^^^^^^^^^^
    IP-MIB::ipAdEntAddr.127.0.0.1 = IpAddress: 127.0.0.1

    [...]

    Received 55 bytes from 127.0.0.1
    0000: 30 35 02 01  00 04 06 70  75 62 6C 69  63 A2 28 02    05.....public.(.
    0016: 04 11 98 0D  CA 02 01 00  02 01 00 30  1A 30 18 06    ...........0.0..
    0032: 10 2B 06 01  02 01 04 14  01 01 81 2C  10 81 6F 81    .+.........,..o.
    0048: 08 40 04 AC  10 EF 88                                 .@.....
             ^^^^^^^^  ^^^^^^^^
    IP-MIB::ipAdEntAddr.172.16.239.136 = IpAddress: 172.16.239.136

Comment 2 Olivier Fourdan 2008-10-06 09:57:26 UTC
Created attachment 319537 [details]
Much less intrusive and simpler patch 

Proposed patch.

This patch fixes just the part that changed in snmplib/snmp_client.c as explained above (and drops all the backport from 5.3)

Comment 3 RHEL Program Management 2008-10-06 10:02:14 UTC
This bugzilla has Keywords: Regression.  

Since no regressions are allowed between releases, 
it is also being proposed as a blocker for this release.  

Please resolve ASAP.

Comment 13 Ruediger Landmann 2009-01-22 06:19:29 UTC
Release note added. If any revisions are required, please set the 
"requires_release_notes" flag to "?" and edit the "Release Notes" field accordingly.
All revisions will be proofread by the Engineering Content Services team.

New Contents:
* the snmpd daemon reported IP address values with an incorrect length of 8 bytes on 64-bit architectures. This has been corrected by asserting within the snmp_client that an IP address has a length of 4 bytes.

Comment 14 Jan Safranek 2009-02-10 16:31:15 UTC
*** Bug 484639 has been marked as a duplicate of this bug. ***

Comment 21 errata-xmlrpc 2009-05-18 20:18:23 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-0984.html