Text  |   XML   |   Visible Warnings:

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

Categories: LANG.MEM.NPD CWE:476
Warning ID: 194.28820
Procedure: readhostfile
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 */ 
hp <= 4095874                                 hp->hd_flag |= HF_OVERLOAD;     /* Null Pointer Dereference */
 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: 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_692699 != 0
&buf[0] <= &$unknown_692698
$unknown_692698 != 0
strlen(&$unknown_692698) != 0
strlen(&$unknown_692698) != 1
((char*)&$unknown_692698)[1] = 36
$input_884 <= 511
$input_884 >= 1
$input_892 = &$unknown_692699
Postconditions
buf[0]' = &$unknown_692699
strlen(&buf[0])' = $input_884
errno' != 0
ff' = &$heap_74513
$heap_74510' = 0
bytes_after(&$heap_74510)' = 32
$heap_74510' is allocated by malloc
$heap_74510' is allocated
bytes_before(&$heap_74510)' = 0
$heap_74512' is allocated by open
$heap_74512' is allocated
$heap_74513' = &$heap_74512 - 4096
bytes_after(&$heap_74513)' = 1028
$heap_74513' is allocated by fopen
$heap_74513' is allocated
bytes_before(&$heap_74513)' = 0
hp' = 0
htp' = &$heap_74510
maxhostid' >= 2
num_addrs' >= 1
p' = &$unknown_692698 + 1




Change Warning 194.28820 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: