Text  |   XML   |   Visible Warnings:

Pvm : Pvm analysis 1 : Leak  at host.c:838

Categories: LANG.ALLOC.LEAK CWE:401 CWE:771 CWE:773
Warning ID: 2607.2641
Procedure: readhostfile
Trace: View
Modified: Wed Sep 2 12:42:12 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/pvm/pvm3/src/host.c
   Enter readhostfile
 820 struct htab * 
 821 readhostfile(fn) 
 822         char *fn;
 823 {
 824         struct htab *htp;
 825         struct hostd *hp;
 826         FILE *ff = 0;
 827         char buf[512];          /* line buffer */ 
 828         int lnum = 0;           /* line counter */ 
 829         int err = 0;            /* error count */ 
 830         struct hostent *he;
 831         char *p;
 832         struct in_addr *my_in_addrs;
 833         int num_addrs;
 834         int i;
 835         int maxhostid = tidhmask >> (ffs(tidhmask) - 1);
 836         struct hostd *defaults = 0;
 837  
allocated inside call838         htp = ht_new(1);     /* Leak */
     Enter readhostfile / ht_new
 483   struct htab * 
 484   ht_new(siz) 
 485           int siz;                /* initial length of ht_hosts[] */ 
 486   {
 487           struct htab *htp;
 488    
 489           if (siz < 1)
 490                   siz = 1;
 491           htp = TALLOC(1, struct htab, "ht1");
 492           BZERO((char*)htp, sizeof(struct htab));   /* Null Pointer Dereference (ID: 2469.2497) */
 493           htp->ht_last = siz;
referenced by returned value494           htp->ht_hosts = TALLOC(siz + 1, struct hostd*, "ht2");
referenced by htp->ht_hosts495           BZERO((char*)htp->ht_hosts, (siz + 1) * sizeof(struct hostd*));   /* Null Pointer Dereference (ID: 2468.2496) */
 496           return htp;
referenced by ht_new$return->ht_hosts497   } 
     Exit readhostfile / ht_new
 839  
 840         /*
 841         * get list of this host's interfaces so we can detect ourself in file 
 842         */ 
 843  
referenced by htp->ht_hosts844         if (iflist(&my_in_addrs, &num_addrs) == -1 || num_addrs < 1) {
 845                 pvmlogprintf("readhostfile() iflist failed\n");
 846                 goto bail;
 847         }
 848  
 849         if (!(ff = fopen(fn, "r"))) {
 850                 pvmlogprintf("readhostfile() %s: can't read\n", fn);
 851                 goto bail;
 852         }
 853  
 854         /* parse each line of host file */ 
 855  
 856         while (fgets(buf, sizeof(buf), ff)) {
 857                 lnum++;
 858                 for (p = buf; *p && isspace(*p); p++);   /* Negative Character Value (ID: 2410.2425) */
 859  
 860                 if (!*p || *p == '#')   /* leading '#' is comment */ 
 861                         continue;
 862  
 863                 if (lnum > maxhostid) {
 864                         pvmlogprintf("readhostfile() %s: too many lines\n", fn);
 865                         err++;
 866                         break;
 867                 }
 868                 hp = hd_new(lnum);
 869  
 870                 while (*p == '&' || *p == '$') {
 871                         if (*p == '&')          /* leading '&' is no-start */ 
 872                                 hp->hd_flag |= HF_NOSTART;   /* Null Pointer Dereference (ID: 2614.2648) */
 873                         if (*p == '$')          /* leading '$' allows overloading host */ 
 874                                 hp->hd_flag |= HF_OVERLOAD;   /* Null Pointer Dereference (ID: 2612.2646) */
 875                         p++;
 876                 }
 877  
 878                 if (parsehost(p, hp)) {
 879                         pvmlogprintf("readhostfile() %s %d: errors\n", fn, lnum);
 880                         err++;
 881                         goto badline;
 882                 }
 883  
 884         /*
 885         * if host == "*", change the default options 
 886         * instead of adding a new host to the list 
 887         */ 
 888  
 889                 if (!strcmp(hp->hd_name, "*")) {   /* Null Pointer Dereference (ID: 2611.2645) */
 890                         if (defaults)
 891                                 hd_unref(defaults);
 892                         defaults = hp;
 893                         continue;
 894                 }
 895  
 896         /* Set unspecified fields of hp to defaults */ 
 897  
 898                 if (defaults)
 899                         applydefaults(hp, defaults);
 900  
 901         /* look up ip addr */ 
 902  
 903                 if (!(he = gethostbyname(hp->hd_aname ? hp->hd_aname : hp->hd_name))) {
 904                         pvmlogprintf("readhostfile() %s %d: %s: can't gethostbyname\n",
 905                                 fn, lnum, hp->hd_name);
 906                         err++;
 907                         goto badline;
 908                 }
 909                 BCOPY(he->h_addr_list[0], (char*)&hp->hd_sad.sin_addr,
 910                         sizeof(struct in_addr));   /* Buffer Overrun (ID: 2609.2643) */
 911  
 912         /* mark master host to not start */ 
 913  
 914                 if (!(hp->hd_flag & HF_OVERLOAD))
 915                         for (i = num_addrs; i-- > 0; ) {
 916                                 if (BCMP((char*)&my_in_addrs[i], (char*)&hp->hd_sad.sin_addr,
 917                                                 sizeof(struct in_addr)) == 0) {
 918                                         hp->hd_flag |= HF_NOSTART;
 919                                         break;
 920                                 }
 921                         }
 922  
 923                 ht_insert(htp, hp);
     Enter readhostfile / ht_insert
referenced by htp->ht_hosts507   ht_insert(htp, hp) 
 508           struct htab *htp;
 509           struct hostd *hp;
 510   {
 511           int hh;
 512           int i;
 513           unsigned long mask = 0, tmpmask;
 514    
 515           int *dsigs;
 516           int ndsigs;
 517           int found;
 518           int d;
 519    
 520           hh = (hp->hd_hostpart & tidhmask) >> (ffs(tidhmask) - 1);
 521    
 522           /* extend ht_hosts[] if no room */ 
 523    
 524           if (hh > htp->ht_last) {
 525                   int n = htp->ht_last;
 526    
 527                   htp->ht_last = (hh * 3) / 2;
 528                   htp->ht_hosts = TREALLOC(htp->ht_hosts, htp->ht_last + 1, struct hostd*);
referenced by $param_1529                   while (++n <= htp->ht_last)
 530                           htp->ht_hosts[n] = 0;   /* Null Pointer Dereference (ID: 2570.2602) */  /* 6 more... */
 531           }
 532    
 533           /* if already have an entry, take this as an update XXX kind of a hack */ 
 534    
 535           if (htp->ht_hosts[hh]) {        /* already have an entry */ 
 536    
 537                   struct hostd *hp2 = htp->ht_hosts[hh];
 538    
 539                   if (hp->hd_name) {
 540                           if (hp2->hd_name)
 541                                   PVM_FREE(hp2->hd_name);
 542                           hp2->hd_name = STRALLOC(hp->hd_name);   /* Null Pointer Dereference (ID: 2474.2502) */
 543                   }
 544                   if (hp->hd_arch) {
 545                           if (hp2->hd_arch)
 546                                   PVM_FREE(hp2->hd_arch);
 547                           hp2->hd_arch = STRALLOC(hp->hd_arch);   /* Null Pointer Dereference (ID: 2473.2501) */
 548                   }
 549                   hp2->hd_dsig = hp->hd_dsig;
 550                   hp2->hd_mtu = hp->hd_mtu;
 551                   hp2->hd_sad = hp->hd_sad;
 552                   hp2->hd_speed = hp->hd_speed;
 553    
 554           } else {                                        /* add new entry */ 
 555    
 556                   htp->ht_hosts[hh] = hp;
 557                   if (hh)
 558                           htp->ht_cnt++;
 559                   hp->hd_ref++;
 560           }
 561    
 562           /* update number of arches */ 
 563    
leaked564           dsigs = TALLOC( htp->ht_cnt, int, "dsigs");
     Exit readhostfile / ht_insert
Preconditions
&$unknown_770444 >= 1
&$unknown_770446 >= 1
&$unknown_770448 >= 512
&$unknown_770449 = 0
((char*)&$heap_39994)[184] = 0
Postconditions
defaults' = 0
err' = 0
ff' = &$heap_39993
fn' = $param_1
ghbn_h_name[0]' = 60
strlen(&ghbn_h_name[0])' = 255
ghbn_h_name[255]' = 0
he' = &stored_hostent.h_name
$heap_39990' = 0
bytes_after(&$heap_39990)' = 40
$heap_39990' is allocated by malloc
$heap_39990' is allocated
bytes_before(&$heap_39990)' = 0
strlen(&$heap_39990)' = 0
((char*)&$heap_39990)[32]' = &$unknown_770449
((char*)&$heap_39990)[4]' >= -1
((char*)&$heap_39990)[4]' <= 1
((char*)&$heap_39990)[8]' = ((char*)&$heap_39990)[8] + 1
$heap_39991' = 0
bytes_after(&$heap_39991)' = 16
$heap_39991' is allocated by malloc
$heap_39991' is allocated
bytes_before(&$heap_39991)' = 0
strlen(&$heap_39991)' = 0
$heap_39992' is allocated by open
$heap_39992' is allocated
((char*)&$heap_39992)[-4096]' is open
$heap_39993' = &$heap_39992 - 4096
bytes_after(&$heap_39993)' = 1028
$heap_39993' is allocated by fopen
$heap_39993' is allocated
$heap_39993' is open
bytes_before(&$heap_39993)' = 0
$heap_39994' = 2
bytes_after(&$heap_39994)' = 200
$heap_39994' is allocated by malloc
bytes_before(&$heap_39994)' = 0
strlen(&$heap_39994)' = 0
((char*)&$heap_39994)[136]' = &$heap_39995
((char*)&$heap_39994)[152]' = 1
((char*)&$heap_39994)[176]' = &$heap_39997
((char*)&$heap_39994)[88]' = 2
((char*)&$heap_39994)[104]' = 1
((char*)&$heap_39994)[108]' = 1
((char*)&$heap_39994)[112]' = &$heap_39996
((char*)&$heap_39994)[120]' = &$heap_39998
$heap_39995' = &$heap_39995
bytes_after(&$heap_39995)' = 184
$heap_39995' is allocated by malloc
$heap_39995' is allocated
bytes_before(&$heap_39995)' = 0
((char*)&$heap_39995)[16]' = 0
((char*)&$heap_39995)[176]' = 0
((char*)&$heap_39995)[24]' = 0
((char*)&$heap_39995)[32]' = 0
((char*)&$heap_39995)[40]' = 0
((char*)&$heap_39995)[8]' = &$heap_39995
bytes_after(&$heap_39996)' = 184
$heap_39996' is allocated by malloc
$heap_39996' is allocated
bytes_before(&$heap_39996)' = 0
((char*)&$heap_39996)[16]' = 0
((char*)&$heap_39996)[176]' = 0
((char*)&$heap_39996)[24]' = 0
((char*)&$heap_39996)[32]' = 0
((char*)&$heap_39996)[40]' = 0
$heap_39997' = &$heap_39997
bytes_after(&$heap_39997)' = 32
$heap_39997' is allocated by malloc
$heap_39997' is allocated
bytes_before(&$heap_39997)' = 0
((char*)&$heap_39997)[16]' = 0
((char*)&$heap_39997)[20]' = 0
((char*)&$heap_39997)[24]' = 0
((char*)&$heap_39997)[8]' = &$heap_39997
bytes_after(&$heap_39998)' = 184
$heap_39998' is allocated by malloc
$heap_39998' is allocated
bytes_before(&$heap_39998)' = 0
((char*)&$heap_39998)[16]' = 0
((char*)&$heap_39998)[176]' = 0
((char*)&$heap_39998)[24]' = 0
((char*)&$heap_39998)[32]' = 0
((char*)&$heap_39998)[40]' = 0
hh' = &$unknown_770448
hp' = &$heap_39994
hp' = &$heap_39994
htp' = &$heap_39990
htp' = &$heap_39990
lnum' = 1
mask' = 0
maxhostid' = &$unknown_770446
n' = 2
num_addrs' = &$unknown_770444
p' = &buf[0]




Change Warning 2607.2641 : Leak

Priority:
State:
Finding:
Owner:
Note: