Text  |   XML   |   Visible Warnings:

Pvm : Pvm analysis 1 : Null Pointer Dereference  at host.c:530

Categories: LANG.MEM.NPD CWE:476
Warning ID: 2608.2642
Procedure: ht_insert
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  
true838         htp = ht_new(1);   /* Leak (ID: 2607.2641) */
 839  
 840         /*
 841         * get list of this host's interfaces so we can detect ourself in file 
 842         */ 
 843  
 844         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  
htp->ht_last < 511923                 ht_insert(htp, hp);
     Enter readhostfile / ht_insert
((char*)$param_1)[4] < 511507   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) {
htp->ht_last < 511525                   int n = htp->ht_last;
 526    
 527                   htp->ht_last = (hh * 3) / 2;
n < 511528                   htp->ht_hosts = TREALLOC(htp->ht_hosts, htp->ht_last + 1, struct hostd*);
 529                   while (++n <= htp->ht_last)
htp->ht_hosts <= 4095530                           htp->ht_hosts[n] = 0;     /* Null Pointer Dereference */  /* 6 more... */
     Exit readhostfile / ht_insert
Preconditions
&$unknown_771491 >= 1
&$unknown_771493 >= 1
&$unknown_771498 >= 2
&$unknown_771499 >= 2
&buf[0] <= &$unknown_771494
$unknown_771494 <= 38
$unknown_771494 >= 36
strlen(&$unknown_771494) != 0
strlen(&$unknown_771494) != 1
((char*)&$unknown_771494)[1] != 0
((char*)&$unknown_771494)[1] != 36
((char*)&$unknown_771494)[1] != 38
strlen(&$unknown_771495) != 0
$input_500 <= 511
$input_500 >= 1
$input_508 <= 38
$input_508 >= 36
Postconditions
buf[0]' = $input_508
strlen(&buf[0])' = $input_500
defaults' = 0
err' = 0
ff' = &$heap_41184
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_41181' = 0
bytes_after(&$heap_41181)' = 40
$heap_41181' is allocated by malloc
$heap_41181' is allocated
bytes_before(&$heap_41181)' = 0
strlen(&$heap_41181)' = 0
((char*)&$heap_41181)[32]' = 0
((char*)&$heap_41181)[4]' = &$unknown_771499
$heap_41182' = 0
bytes_after(&$heap_41182)' = 16
$heap_41182' is allocated by malloc
$heap_41182' is allocated
bytes_before(&$heap_41182)' = 0
strlen(&$heap_41182)' = 0
$heap_41183' is allocated by open
$heap_41183' is allocated
((char*)&$heap_41183)[-4096]' is open
$heap_41184' = &$heap_41183 - 4096
bytes_after(&$heap_41184)' = 1028
$heap_41184' is allocated by fopen
$heap_41184' is allocated
$heap_41184' is open
bytes_before(&$heap_41184)' = 0
$heap_41185' = 1
bytes_after(&$heap_41185)' = 200
$heap_41185' is allocated by malloc
$heap_41185' is allocated
bytes_before(&$heap_41185)' = 0
strlen(&$heap_41185)' = 0
((char*)&$heap_41185)[136]' = &$heap_41186
((char*)&$heap_41185)[152]' = 1
((char*)&$heap_41185)[176]' = &$heap_41188
((char*)&$heap_41185)[8]' = &$unknown_771495
((char*)&$heap_41185)[88]' = 2
((char*)&$heap_41185)[104]' = 1
((char*)&$heap_41185)[108]' = 1
((char*)&$heap_41185)[112]' = &$heap_41187
((char*)&$heap_41185)[120]' = &$heap_41189
$heap_41186' = &$heap_41186
bytes_after(&$heap_41186)' = 184
$heap_41186' is allocated by malloc
$heap_41186' is allocated
bytes_before(&$heap_41186)' = 0
((char*)&$heap_41186)[16]' = 0
((char*)&$heap_41186)[176]' = 0
((char*)&$heap_41186)[24]' = 0
((char*)&$heap_41186)[32]' = 0
((char*)&$heap_41186)[40]' = 0
((char*)&$heap_41186)[8]' = &$heap_41186
bytes_after(&$heap_41187)' = 184
$heap_41187' is allocated by malloc
$heap_41187' is allocated
bytes_before(&$heap_41187)' = 0
((char*)&$heap_41187)[16]' = 0
((char*)&$heap_41187)[176]' = 0
((char*)&$heap_41187)[24]' = 0
((char*)&$heap_41187)[32]' = 0
((char*)&$heap_41187)[40]' = 0
$heap_41188' = &$heap_41188
bytes_after(&$heap_41188)' = 32
$heap_41188' is allocated by malloc
$heap_41188' is allocated
bytes_before(&$heap_41188)' = 0
((char*)&$heap_41188)[16]' = 0
((char*)&$heap_41188)[20]' = 0
((char*)&$heap_41188)[24]' = 0
((char*)&$heap_41188)[8]' = &$heap_41188
bytes_after(&$heap_41189)' = 184
$heap_41189' is allocated by malloc
$heap_41189' is allocated
bytes_before(&$heap_41189)' = 0
((char*)&$heap_41189)[16]' = 0
((char*)&$heap_41189)[176]' = 0
((char*)&$heap_41189)[24]' = 0
((char*)&$heap_41189)[32]' = 0
((char*)&$heap_41189)[40]' = 0
hh' = &$unknown_771498
hp' = &$heap_41185
hp' = &$heap_41185
htp' = &$heap_41181
htp' = &$heap_41181
i' = &$unknown_771491 - 1
lnum' = 1
mask' = 0
maxhostid' = &$unknown_771493
my_in_addrs' = &$unknown_771497
n' = 2
num_addrs' = &$unknown_771491
p' = &$unknown_771494 + 1




Change Warning 2608.2642 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: