Text  |   XML   |   Visible Warnings:

Irssi : Irssi analysis 1 : Leak  at network.c:420

Categories: LANG.ALLOC.LEAK CWE:401 CWE:771 CWE:773
Warning ID: 2087.2087
Procedure: net_gethostbyname
Trace: View
Modified: Wed Sep 2 11:51:07 2009   show details
 
Priority: None
State: None
Finding: None
Owner: None
  edit properties

Legend [ X ]
Warning Location
Contributes
Parse Error
Other Warning
Two or More Loop Iterations
On Execution Path
Comment
Macro
Preprocessor
Include
Keyword
Preprocessed Away

Source  |  Language: C Hide Legend     
ProblemLineSource
   /u1/paul/SATE/2010/c/irssi/irssi-0.8.14/src/core/network.c
   Enter net_gethostbyname
 399 int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6) 
 400 {
 401 #ifdef HAVE_IPV6 
 402         union sockaddr_union *so;
 403         struct addrinfo hints, *ai, *ailist;
 404         int ret, count_v4, count_v6, use_v4, use_v6;
 405 #else 
 406         struct hostent *hp;
 407         int count; 
 408 #endif 
 409  
 410         g_return_val_if_fail(addr != NULL, -1);
 411  
 412         memset(ip4, 0, sizeof(IPADDR));
 413         memset(ip6, 0, sizeof(IPADDR));
 414  
 415 #ifdef HAVE_IPV6 
 416         memset(&hints, 0, sizeof(struct addrinfo));
 417         hints.ai_socktype = SOCK_STREAM;
 418  
 419         /* save error to host_error for later use */ 
referenced by (&ailist->ai_addrlen)[1]420         ret = getaddrinfo(addr, NULL, &hints, &ailist);     /* Leak */
 421         if (ret != 0)
 422                 return ret;
 423  
 424         /* count IPs */ 
 425         count_v4 = count_v6 = 0;
 426         for (ai = ailist; ai != NULL; ai = ai->ai_next) {   /* Buffer Overrun (ID: 2088.2089) */
 427                 if (ai->ai_family == AF_INET)
 428                         count_v4++;
 429                 else if (ai->ai_family == AF_INET6)
 430                         count_v6++;
 431         }
 432  
 433         if (count_v4 == 0 && count_v6 == 0)
 434                 return HOST_NOT_FOUND; /* shouldn't happen? */ 
 435  
 436         /* if there are multiple addresses, return random one */ 
 437         use_v4 = count_v4 <= 1 ? 0 : rand() % count_v4;
 438         use_v6 = count_v6 <= 1 ? 0 : rand() % count_v6;
 439  
 440         count_v4 = count_v6 = 0;
 441         for (ai = ailist; ai != NULL; ai = ai->ai_next) {   /* Buffer Overrun (ID: 2088.2088) */
 442                 so = (union sockaddr_union *) ai->ai_addr;
 443  
 444                 if (ai->ai_family == AF_INET) {
   ...
 465  
 466         if (count == 0)
 467                 return HOST_NOT_FOUND; /* shouldn't happen? */ 
 468  
 469         /* if there are multiple addresses, return random one */ 
 470         ip4->family = AF_INET;
 471         memcpy(&ip4->ip, hp->h_addr_list[rand() % count], 4);
 472  
 473         return 0; 
 474 #endif 
 475 } 
Preconditions
$param_1 >= 1




Change Warning 2087.2087 : Leak

Priority:
State:
Finding:
Owner:
Note: