Possible mistakes
Opened this issue · 0 comments
Bbulatov commented
Hello!
During the static analysis was found some possible mistake:
- After having been compared to a NULL value at getnodeaddr.c:174, pointer '(**ifap).ifa_addr' is dereferenced at getnodeaddr.c:193.
/* hunt for IPv4 interface */
for (ifa = ifap; ifa; ifa = ifa->ifa_next)
{
if (NULL == ifa->ifa_addr ||
AF_INET != ifa->ifa_addr->sa_family)
continue;
if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == ((struct in_addr*)(he->h_addr_list[0]))->s_addr)
{
goto ipv4_found;
}
}
pgm_freeifaddrs (ifap);
pgm_set_error (error,
PGM_ERROR_DOMAIN_IF,
PGM_ERROR_NONET,
_("Discovering primary IPv4 network interface."));
return FALSE;
ipv4_found:
/* hunt for IPv6 interface */
for (ifa6 = ifap; ifa6; ifa6 = ifa6->ifa_next)
{
if (AF_INET6 != ifa6->ifa_addr->sa_family)
continue;
if (0 == strcmp (ifa->ifa_name, ifa6->ifa_name))
{
goto ipv6_found;
}
}
- Expression 'elapsed', used as divisor at time.c:869, may have a zero value when variable 'stop - start' has value '0'. Check at time.c:864 does not prevent this error.
elapsed = stop - start;
if (elapsed > calibration_usec) {
/* cpu > 1 Ghz */
tsc_khz = (elapsed * 1000) / calibration_usec;
} else {
/* cpu < 1 Ghz */
tsc_khz = -( (calibration_usec * 1000) / elapsed );
}
- Dynamic memory, referenced by 'result', is allocated at getnodeaddr.c:103 by calling function 'pgm_getnodeaddr' at getnodeaddr.c:244 and lost at getnodeaddr.c:259.
if (!pgm_getnodeaddr (family, &result, error)) {
pgm_prefix_error (error,
_("Enumerating node address: "));
return FALSE;
}
/* iff one address return that independent of multicast support */
if (NULL == result->ai_next) {
pgm_return_val_if_fail (cnt >= (socklen_t)result->ai_addrlen, FALSE);
memcpy (addr, result->ai_addr, result->ai_addrlen);
pgm_freenodeaddr (result);
return TRUE;
}
if (!pgm_getifaddrs (&ifap, error)) {
pgm_prefix_error (error,
_("Enumerating network interfaces: "));
return FALSE;
}