From: SourceForge.net <no...@so...> - 2011-10-26 02:12:03
|
Bugs item #3428506, was opened at 2011-10-26 04:12 Message generated for change (Tracker Item Submitted) made by dlukes You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112694&aid=3428506&group_id=12694 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: library Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Dan Lukes (dlukes) Assigned to: Nobody/Anonymous (nobody) Summary: netsnmp_gethostbyaddr() broken (called inconsistently) Initial Comment: netsnmp_gethostbyaddr() in snmplib/system.c is broken, so functions that depend on it (for example %A and %B formats of snmptrapd) doesn't work. Following fragment is copied from git (HEAD): ------------------------------ 928 struct hostent * 929 netsnmp_gethostbyaddr(const void *addr, socklen_t len, int type) 930 { ... 933 struct sockaddr_in *saddr_in = 934 NETSNMP_REMOVE_CONST(struct sockaddr_in *,addr); 935 936 DEBUGMSGTL(("dns:gethostbyaddr", "resolving { AF_INET, %s:%hu }\n", 937 inet_ntoa(saddr_in->sin_addr), ntohs(saddr_in->sin_port))); ... 959 hp = gethostbyaddr((const void*) &saddr_in->sin_addr, 960 sizeof(struct in_addr), AF_INET); ------------------------------ A: The AF_INET case: ==================== The netsnmp_gethostbyaddr() is called with addr of type (struct in_addr), len=sizeof(struct in_addr) and type = AF_INET: ./apps/snmpnetstat/route.c: hp = netsnmp_gethostbyaddr((char *)&in, sizeof (struct in_addr), ./apps/snmpnetstat/inet.c: hp = netsnmp_gethostbyaddr((char *)inp, sizeof (*inp), ./apps/snmptrapd_log.c: host = netsnmp_gethostbyaddr((char *) pdu->agent_addr, 4, AF_INET); ./apps/snmptrapd_log.c: host = netsnmp_gethostbyaddr((char *) pdu->agent_addr, 4, AF_INET); ./agent/mibgroup/disman/nslookup/lookupCtlTable.c: lookup = netsnmp_gethostbyaddr(&addr_in, sizeof(addr_in), AF_INET); ./snmplib/transports/snmpIPv4BaseDomain.c: host = netsnmp_gethostbyaddr((char *)&to->sin_addr, 4, AF_INET); saddr_in variable is intialized incorrectly on line 933 - structures in_addr and sockaddr_in are not compatible (at least, they are not guaranteed to be compatible) so it's not possible to cast one of them to other. Resulting saddr_in->sin_addr_in does not contain value of addr. The gethostbyaddr on line 959 is called with uninitialized value and fail. The same is valid for val_gethostbyaddr() on 941 B: The AF_INET6 case: ==================== The netsnmp_gethostbyaddr() is called with addr of type (struct in_addr6), len=sizeof(struct in_addr6) and type = AF_INET6: ./agent/mibgroup/disman/nslookup/lookupCtlTable.c: lookup = netsnmp_gethostbyaddr(&addr_in6, sizeof(addr_in6), AF_INET6); ./agent/mibgroup/disman/ping/pingCtlTable.c: hp = netsnmp_gethostbyaddr((__u8 *) addr, sizeof(struct in6_addr), ./agent/mibgroup/disman/nslookup/lookupCtlTable.c: lookup = netsnmp_gethostbyaddr(&addr_in6, sizeof(addr_in6), AF_INET6); ./apps/snmpnetstat/inet6.c: hp = netsnmp_gethostbyaddr((const char *)in6p, sizeof(*in6p), netsnmp_gethostbyaddr() is completelly broken in such case - it ignore supplied type and treat all calls as IPv4 ======================================== We need either: 1. patch netsnmp_gethostbyaddr() to convert in_addr to sockaddr_in correctly and implement IPv6 handling or 2. claim it obsolete, remove it and replace all calls to it by calls to netsnmp_getaddrinfo() My favourite is [2], but I'm not as familiar with net-snmp project as necesarry for such kind of decision ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112694&aid=3428506&group_id=12694 |