Text  |   XML   |   Visible Warnings:

pvm3.4.6 : pvm3.4.6 analysis 2 : Buffer Overrun  at host.c:910

Categories: LANG.MEM.BO CWE:120 CWE:121 CWE:122 CWE:126
Warning ID: 22064.28817
Procedure: readhostfile
Trace: view
Modified: Thu Nov 26 11:28: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
   /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                 }
 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: 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  
 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)
$input_8500 < 3899                         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,
bytes_after(*he->h_addr_list) < 4910                         sizeof(struct in_addr));     /* Buffer Overrun */
 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_691194 != 0
&$unknown_691195 >= &buf[0] + 1
$unknown_691195 <= 38
$unknown_691195 >= 36
strlen(&$unknown_691195) != 0
strlen(&$unknown_691195) != 1
((char*)&$unknown_691195)[1] != 0
((char*)&$unknown_691195)[1] != 36
((char*)&$unknown_691195)[1] != 38
$unknown_691196 <= 42
((char*)&$heap_73372)[116] = 0
$input_12 >= 0
$input_8476 >= 0
$input_8500 >= 0
$input_884 <= 511
$input_884 >= 1
$input_892 = &$unknown_691194
Postconditions
buf[0]' = &$unknown_691194
strlen(&buf[0])' = $input_884
defaults' = &$unknown_691197
ff' = &$heap_73370
he' = &$heap_73379
$heap_73367' = 0
bytes_after(&$heap_73367)' = 32
$heap_73367' is allocated by malloc
$heap_73367' is allocated
bytes_before(&$heap_73367)' = 0
$heap_73369' is allocated by open
$heap_73369' is allocated
$heap_73370' = &$heap_73369 - 4096
bytes_after(&$heap_73370)' = 1028
$heap_73370' is allocated by fopen
$heap_73370' is allocated
bytes_before(&$heap_73370)' = 0
$heap_73371' = &$heap_73371
bytes_after(&$heap_73371)' = 120
$heap_73371' is allocated by malloc
$heap_73371' is allocated
bytes_before(&$heap_73371)' = 0
((char*)&$heap_73371)[16]' = 0
((char*)&$heap_73371)[20]' = 0
((char*)&$heap_73371)[4]' = &$heap_73371
((char*)&$heap_73371)[8]' = 0
((char*)&$heap_73371)[116]' = 0
((char*)&$heap_73371)[12]' = 0
$heap_73372' = 1
bytes_after(&$heap_73372)' = 124
$heap_73372' is allocated by malloc
$heap_73372' is allocated
bytes_before(&$heap_73372)' = 0
((char*)&$heap_73372)[56]' = 2
((char*)&$heap_73372)[60]' = $input_8508
((char*)&$heap_73372)[72]' = 1
((char*)&$heap_73372)[76]' = 1
((char*)&$heap_73372)[80]' = &$heap_73371
((char*)&$heap_73372)[8]' = &$unknown_691196
((char*)&$heap_73372)[84]' = &$heap_73374
((char*)&$heap_73372)[92]' = &$heap_73373
((char*)&$heap_73372)[100]' = 1
((char*)&$heap_73372)[112]' = 0
bytes_after(&$heap_73373)' = 120
$heap_73373' is allocated by malloc
$heap_73373' is allocated
bytes_before(&$heap_73373)' = 0
((char*)&$heap_73373)[16]' = 0
((char*)&$heap_73373)[20]' = 0
((char*)&$heap_73373)[8]' = 0
((char*)&$heap_73373)[116]' = 0
((char*)&$heap_73373)[12]' = 0
$heap_73374' = &$heap_73374
bytes_after(&$heap_73374)' = 120
$heap_73374' is allocated by malloc
$heap_73374' is allocated
bytes_before(&$heap_73374)' = 0
((char*)&$heap_73374)[16]' = 0
((char*)&$heap_73374)[20]' = 0
((char*)&$heap_73374)[4]' = &$heap_73374
((char*)&$heap_73374)[8]' = 0
((char*)&$heap_73374)[116]' = 0
((char*)&$heap_73374)[12]' = 0
$heap_73375' = $input_444
bytes_after(&$heap_73375)' = $input_12 + 1
$heap_73375' is allocated by malloc
$heap_73375' is a non-heap object
bytes_before(&$heap_73375)' = 0
strlen(&$heap_73375)' = $input_12
$heap_73376' = &$heap_73378
$heap_73376' is a non-heap object
bytes_before(&$heap_73376)' = 0
$heap_73377' = $input_8508
bytes_after(&$heap_73377)' = $input_8500 + 1
$heap_73377' is allocated by malloc
$heap_73377' is a non-heap object
bytes_before(&$heap_73377)' = 0
strlen(&$heap_73377)' = $input_8500
$heap_73378' = $input_8484
bytes_after(&$heap_73378)' = $input_8476 + 1
$heap_73378' is allocated by malloc
$heap_73378' is a non-heap object
bytes_before(&$heap_73378)' = 0
strlen(&$heap_73378)' = $input_8476
$heap_73379' = &$heap_73375
bytes_after(&$heap_73379)' = 1024
$heap_73379' is a non-heap object
bytes_before(&$heap_73379)' = 0
((char*)&$heap_73379)[16]' = &$heap_73380
((char*)&$heap_73379)[4]' = &$heap_73376
$heap_73380' = &$heap_73377
$heap_73380' is a non-heap object
bytes_before(&$heap_73380)' = 0
hp' = &$heap_73372
htp' = &$heap_73367
last_rv' = &$heap_73379
maxhostid' >= 2
num_addrs' >= 1
p' = &$unknown_691195 + 1




Change Warning 22064.28817 : Buffer Overrun

Priority:
State:
Finding:
Owner:
Note: