Text  |   XML   |   Visible Warnings:

pvm3.4.6 : pvm3.4.6 analysis 2 : Null Pointer Dereference  at host.c:804

Categories: LANG.MEM.NPD CWE:476
Warning ID: 195.28821
Procedure: parsehost
Trace: view
Modified: Thu Nov 26 11:28:08 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
   /kat0/fletcher/SATE/2010/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  
 838         htp = ht_new(1);
 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: 1.28573) */
 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                 }
true868                 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: 196.28822) */
 873                         if (*p == '$')          /* leading '$' allows overloading host */ 
 874                                 hp->hd_flag |= HF_OVERLOAD;   /* Null Pointer Dereference (ID: 194.28820) */
 875                         p++;
 876                 }
 877  
hp <= 4095878                 if (parsehost(p, hp)) {
     Enter readhostfile / parsehost
 726   parsehost(buf, hp) 
 727           char *buf;
 728           struct hostd *hp;
 729   {
 730           char *av[10];           /* parsed words */ 
 731           int ac;
 732           int err = 0;
 733    
 734           ac = sizeof(av)/sizeof(av[0]);
 735           if (acav(buf, &ac, av)) {
 736                   pvmlogprintf("parsehost(): line too long\n");
 737                   goto bad;
 738           }
 739           if (!ac)
 740                   goto bad;
 741    
 742           /* add options to host descriptor */ 
 743    
 744           while (--ac > 0) {
 745                   if (!strncmp(av[ac], "lo=", 3)) {
 746                           if (hp->)
 747                                   PVM_FREE(hp->);
 748                           hp-> = STRALLOC(av[ac] + 3);   /* Null Pointer Dereference (ID: 50.28635) */
 749                           continue;
 750                   }
 751                   if (!strncmp(av[ac], "dx=", 3)) {
 752                           if (hp->hd_dpath)
 753                                   PVM_FREE(hp->hd_dpath);
 754                           hp->hd_dpath = STRALLOC(av[ac] + 3);   /* Null Pointer Dereference (ID: 49.28634) */
     ...
 791                   }
 792                   if (!strncmp(av[ac], "id=", 3)) {
 793                           if (hp->hd_vmid)
 794                                   PVM_FREE(hp->hd_vmid);
 795                           hp->hd_vmid = STRALLOC(av[ac] + 3);   /* Null Pointer Dereference (ID: 43.28628) */
 796                           continue;
 797                   }
 798                   pvmlogprintf("parsehost(): unknown option \"%s\"\n", av[ac]);
 799                   err++;
 800           }
 801           if (err)
 802                   goto bad;
 803    
hp <= 4095804           if (hp->hd_name)     /* Null Pointer Dereference */  /* Null Pointer Dereference (ID: 22056.28727) */
     Exit readhostfile / parsehost
 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: 193.28819) */
 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: 22064.28817) */
 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);
 924                 hd_unref(hp);
 925                 continue;
 926  
 927 badline: 
 928                 hd_unref(hp);
Preconditions
&$unknown_693300 >= &buf[0]
&$unknown_693301 != 0
&$unknown_693302 != 0
&$unknown_693302 <= 1
$unknown_693300 != 0
strlen(&$unknown_693300) != 0
strlen(&$unknown_693300) != 1
((char*)&$unknown_693300)[1] != 0
((char*)&$unknown_693300)[1] != 35
((char*)&$unknown_693300)[1] != 36
((char*)&$unknown_693300)[1] != 38
$input_884 <= 511
$input_884 >= 1
$input_892 = &$unknown_693301
Postconditions
ac' = &$unknown_693302 - 1
buf' = &$unknown_693300 + 1
buf[0]' = &$unknown_693301
strlen(&buf[0])' = $input_884
err' = 0
errno' != 0
ff' = &$heap_74736
$heap_74733' = 0
bytes_after(&$heap_74733)' = 32
$heap_74733' is allocated by malloc
$heap_74733' is allocated
bytes_before(&$heap_74733)' = 0
$heap_74735' is allocated by open
$heap_74735' is allocated
$heap_74736' = &$heap_74735 - 4096
bytes_after(&$heap_74736)' = 1028
$heap_74736' is allocated by fopen
$heap_74736' is allocated
bytes_before(&$heap_74736)' = 0
hp' = 0
hp' = 0
htp' = &$heap_74733
maxhostid' >= 2
num_addrs' >= 1
p' = &$unknown_693300 + 1




Change Warning 195.28821 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: