Text  |   XML   |   Visible Warnings:

pvm3.4.6 : pvm3.4.6 analysis 2 : Buffer Overrun  at ddpro.c:1071

Categories: LANG.MEM.BO CWE:120 CWE:121 CWE:122 CWE:126
Warning ID: 107.28713
Procedure: addhosts
Trace: view
Modified: Thu Nov 26 11:27:32 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/ddpro.c
   Enter addhosts
$input_29676 > $unknown_6322055 - 62840 addhosts(mp, rmp) 
 841         struct pmsg *mp;        /* the request message */ 
 842         struct pmsg *rmp;       /* reply message blank */ 
 843 {
 844         struct hostd *hp, *hp2;
 845         struct pmsg *mp2;
$input_29708 > $unknown_6322087 - 62846         struct waitc *wp = 0;
$input_29740 > $unknown_6322119 - 62847         struct waitc_add *wxp = 0;
 848         int i, j;
 849         int count;
 850         int ngood;
 851         int ntid;
 852         struct hostent *he;
$input_29772 > $unknown_6322151 - 62853         int maxhostid = (tidhmask >> ffs(tidhmask) - 1);
 854         int hh;
 855         int pid;
 856         int *tids;
 857         char *winpvmdpath;
 858         char *pvmdpath;
 859         char *vmid;
 860         char *buf;
 861         int len;
 862  
 863         /*
 864         * have to lock this for 2 reasons:
 865         *  1. system can't handle overlapping host table updates,
 866         *  2. the new host tids aren't reserved 
 867         */ 
$input_29900 > $unknown_6322273 - 62868         if (busyadding) {
 869 /*
 870                 pvmlogerror("addhosts() already adding new hosts\n");
 871 */ 
 872                 pkint(rmp, PvmAlready);
 873                 sendmessage(rmp);
 874                 return 0;
 875         }
 876  
$input_29932 > $unknown_6322301 - 62877         busyadding = 1;
 878  
 879         /* sanity check count */ 
 880  
$input_29964 > $unknown_6322329 - 62881         if (upkint(mp, &count) || count < 1 || count > maxhostid) {
 882                 pvmlogerror("addhosts() bad msg format\n");
 883                 goto bad;
 884         }
 885  
 886         /*
 887         * make wait context, extract host list from message,
 888         */ 
 889  
$input_30188 > $unknown_6322489 - 62890         wp = wait_new(WT_HOSTSTART);
$input_30316 > $unknown_6322569 - 62891         wp->wa_tid = mp->m_src;
$input_30348 > $unknown_6322591 - 62892         wp->wa_dep = mp->m_wid;
$input_30380 > $unknown_6322611 - 62893         wxp = TALLOC(1, struct waitc_add, "waix");
$input_30508 > $unknown_6322691 - 62894         wxp->w_num = count;   /* Null Pointer Dereference (ID: 22059.28730) */
$input_30540 > $unknown_6322711 - 62895         wxp->w_hosts = TALLOC(count, struct hostd *, "waiv");   /* Integer Overflow of Allocation Size (ID: 22058.28729) */
$input_30668 > $unknown_6322797 - 62896         BZERO((char*)wxp->w_hosts, count * sizeof(struct hostd *));   /* Null Pointer Dereference (ID: 22057.28728) */
$input_30796 > $unknown_6322883 - 62897         wp->wa_spec = (void *)wxp;
 898  
$input_30828 > $unknown_6322903 - 62899         for (i = 0; i < count; i++) {
$input_30924 > $unknown_6322965 - 62900                 hp = hd_new(0);
$input_31052 > $unknown_6323045 - 62901                 wxp->w_hosts[i] = hp;
$input_31084 > $unknown_6323065 - 62902                 if (upkstralloc(mp, &buf)) {
 903                         pvmlogerror("addhosts() bad msg format\n");
 904                         goto bad;
 905                 }
$input_31244 > $unknown_6323189 - 62906                 if (parsehost(buf, hp)) {
 907                         hp->hd_err = PvmBadParam;   /* Null Pointer Dereference (ID: 22054.28725) */
 908  
$input_31404 > $unknown_6323291 - 62909                 } else {
 910  
 911                 /* Set unspecified fields from hostfile if available */ 
 912  
$input_31436 > $unknown_6323309 - 62913                         if (filehosts &&
 914                                         ((hp2 = nametohost(filehosts, hp->hd_name))   /* Null Pointer Dereference (ID: 22053.28724) */
 915                                         || (hp2 = filehosts->ht_hosts[0])))
 916                                 applydefaults(hp, hp2);
 917                 }
$input_31468 > $unknown_6323329 - 62918                 PVM_FREE(buf);
 919         }
 920  
 921         /*
 922         * verify we have a chance to add these babies...
 923         * check whether our IP is "real" or just loopback 
 924         */ 
 925  
$input_31596 > $unknown_6323413 - 62926         hp = hosts->ht_hosts[hosts->ht_local];
 927  
$input_31628 > $unknown_6323437 - 62928         if ( hp->hd_sad.sin_addr.s_addr == htonl(0x7f000001) ) {
 929  
 930                 /* damn, we're hosed.  bail on host adds with new */ 
 931                 /* PvmIPLoopback error code... */ 
 932  
$input_31788 > $unknown_6323549 - 62933                 for (i = 0; i < count; i++) {
$input_31884 > $unknown_6323605 - 62934                         hp = wxp->w_hosts[i];
$input_31916 > $unknown_6323625 - 62935                         if (hp->hd_err)
$input_31948 > $unknown_6323641 - 62936                                 continue;
 937                         hp->hd_err = PvmIPLoopback;
 938                 }
 939         }
 940  
 941         /*
 942         * lookup IP addresses  XXX we already have some of them 
 943         */ 
 944  
$input_32044 > $unknown_6323695 - 62945         ngood = 0;
$input_32076 > $unknown_6323715 - 62946         for (i = 0; i < count; i++) {
$input_32172 > $unknown_6323767 - 62947                 hp = wxp->w_hosts[i];
$input_32204 > $unknown_6323785 - 62948                 if (hp->hd_err)
 949                         continue;
 950  
$input_32236 > $unknown_6323807 - 62951                 if (he = gethostbyname(hp->hd_aname ? hp->hd_aname : hp->hd_name)) {
 952                         BCOPY(he->h_addr_list[0], (char*)&hp->hd_sad.sin_addr,
$input_12 > $unknown_6323931 - 62953                                         sizeof(struct in_addr));   /* Buffer Overrun (ID: 22052.28723) */
 954  
 955                 } else {
 956                         if (pvmdebmask & PDMSTARTUP) {
 957                                 pvmlogprintf( 
 958                                                 "start_slaves() can't gethostbyname: %s\n",
 959                                                 hp->hd_name);
 960                         }
 961                         hp->hd_err = PvmNoHost;
 962                         continue;
 963                 }
 964  
 965         /* make sure it's not already configured */ 
 966  
$input_12 > $unknown_6323999 - 62967                 if (!(hp->hd_flag & HF_OVERLOAD)) {
$input_12 > $unknown_6324017 - 62968                         for (hh = hosts->ht_last; hh > 0; hh--)
$input_12 > $unknown_6324067 - 62969                                 if ((hp2 = hosts->ht_hosts[hh]) 
 970                                 && (hp2->hd_sad.sin_addr.s_addr == hp->hd_sad.sin_addr.s_addr)) {
 971                                         hp->hd_err = PvmDupHost;
 972                                         break;
 973                                 }
$input_12 > $unknown_6324141 - 62974                         if (hp->hd_err)
 975                                 continue;
 976  
 977         /* make sure new ones aren't duplicated */ 
 978  
$input_12 > $unknown_6324155 - 62979                         for (j = i; j-- > 0; )
 980                                 if (hp->hd_sad.sin_addr.s_addr 
 981                                 == wxp->w_hosts[j]->hd_sad.sin_addr.s_addr) {
 982                                         hp->hd_err = PvmDupHost;
 983                                         break;
 984                                 }
$input_12 > $unknown_6324229 - 62985                         if (hp->hd_err)
 986                                 continue;
 987                 }
 988  
$input_12 > $unknown_6324241 - 62989                 ngood++;
 990         }
 991  
 992         /*
 993         * assign tids  XXX these are unreserved until hosts are added...
 994         */ 
 995  
$input_12 > $unknown_6324293 - 62996         ntid = ngood;
$input_12 > $unknown_6324305 - 62997         tids = TALLOC(ngood, int, "xxx");   /* Integer Overflow of Allocation Size (ID: 22051.28722) */
$input_12 > $unknown_6324353 - 62998         hostids_new(&ntid, tids);
$input_12 > $unknown_6324389 - 62999         if (ntid < ngood) {
$input_12 > $unknown_6324401 - 621000                 pvmlogerror("addhosts() out of hostids\n");
$input_12 > $unknown_6324425 - 621001                 ngood = ntid;
 1002         }
$input_12 > $unknown_6324437 - 621003         for (j = i = 0; i < count; i++) {
$input_12 > $unknown_6324489 - 621004                 hp = wxp->w_hosts[i];
$input_12 > $unknown_6324501 - 621005                 if (hp->hd_err)
$input_12 > $unknown_6324513 - 621006                         continue;
 1007                 if (j < ntid)
 1008                         hp->hd_hostpart = tids[j++];   /* Null Pointer Dereference (ID: 22048.28719) */  /* Uninitialized Variable (ID: 22049.28720) */
 1009                 else 
 1010                         hp->hd_err = PvmOutOfRes;
 1011         }
$input_12 > $unknown_6324549 - 621012         PVM_FREE(tids);   /* Free Null Pointer (ID: 22047.28718) */
 1013  
 1014 /*
 1015         if (!ngood) {
 1016                 XXX don't really need to send the message 
 1017         }
 1018 */ 
 1019  
 1020         /* keep stub reply message to caller */ 
 1021  
$input_12 > $unknown_6324573 - 621022         wp->wa_mesg = rmp;
 1023  
 1024         /* make request message and send to hoster or pvmd' */ 
 1025  
$input_12 > $unknown_6324585 - 621026         mp2 = mesg_new(0);
$input_12 > $unknown_6324633 - 621027         mp2->m_wid = wp->wa_wid;   /* Null Pointer Dereference (ID: 22046.28717) */
$input_12 > $unknown_6324645 - 621028         pkint(mp2, ngood);
$input_12 > $unknown_6324685 - 621029         if (!(pvmdpath = getenv("PVM_DPATH")))
 1030                 pvmdpath = PVMDPATH;
strlen(pvmdpath) > $unknown_6324745 - 621031         if (!(winpvmdpath = getenv("PVM_WINDPATH")))
 1032                 winpvmdpath = WINPVMDPATH;
strlen(pvmdpath) > $unknown_6324805 - 621033         for (i = 0; i < count; i++) {
strlen(pvmdpath) > $unknown_6324841 - 621034                 hp = wxp->w_hosts[i];
strlen(pvmdpath) > $unknown_6324853 - 621035                 if (hp->hd_err)
 1036                         continue;
strlen(pvmdpath) > $unknown_6324865 - 621037                 pkint(mp2, hp->hd_hostpart);
strlen(pvmdpath) > $unknown_6324907 - 621038                 pkstr(mp2, hp->hd_sopts ? hp->hd_sopts : "");
 1039  
strlen(pvmdpath) > $unknown_6324971 - 621040                 if (hp->) {
 1041                         len = strlen(hp->) 
 1042                                 + strlen((hp->hd_aname ? hp->hd_aname : hp->hd_name)) 
 1043                                 + 2;
 1044                         buf = TALLOC( len, char, "hdl" );
 1045                         sprintf(buf, "%s@%s", hp->,
 1046                                         (hp->hd_aname ? hp->hd_aname : hp->hd_name));   /* Null Pointer Dereference (ID: 110.28715) */
 1047                 }
strlen(pvmdpath) > $unknown_6324983 - 621048                 else 
 1049                         buf = STRALLOC( (hp->hd_aname 
strlen(pvmdpath) > $unknown_6324995 - 621050                                         ? hp->hd_aname : hp->hd_name) );   /* Null Pointer Dereference (ID: 22045.28716) */
strlen(pvmdpath) > $unknown_6325197 - 621051                 pkstr(mp2, buf);
strlen(pvmdpath) > $unknown_6325233 - 621052                 PVM_FREE(buf);
 1053  
 1054                 /* default unix dpath */ 
strlen(pvmdpath) > $unknown_6325255 - 621055                 len = strlen( (hp->hd_dpath ? hp->hd_dpath : pvmdpath) ) + 1 
strlen(pvmdpath) > $unknown_6325315 - 621056                         + strlen( (hp->hd_sopts && !strcmp(hp->hd_sopts, "ms") 
strlen(pvmdpath) > $unknown_6325387 - 621057                                         ? "-S" : "-s") ) + 1 
strlen(pvmdpath) > $unknown_6325469 - 621058                         + 2 + 16 + 1 
strlen(pvmdpath) > $unknown_6325435 - 621059                         + 2 + strlen( hp->hd_name ) + 1 
strlen(pvmdpath) > $unknown_6325469 - 621060                         + 5 * ( 16 + 1 );
strlen(pvmdpath) > len - 621061                 buf = TALLOC( len, char, "hdall" );
 1062                 (void)sprintf(buf, "%s %s -d0x%x -n%s %d %s %d",
strlen(pvmdpath) > bytes_after(buf) - 431063                                 (hp->hd_dpath ? hp->hd_dpath : pvmdpath),
 1064                                 (hp->hd_sopts && !strcmp(hp->hd_sopts, "ms") 
 1065                                         ? "-S" : "-s"),
 1066                                 pvmdebmask,
 1067                                 hp->hd_name,
strlen(pvmdpath) > bytes_after(buf) - 451068                                 hosts->ht_master,
 1069                                 inadport_hex( 
 1070                                         &hosts->ht_hosts[hosts->ht_master]->hd_sad),
strlen(pvmdpath) > bytes_after(buf) - 621071                                 hosts->ht_hosts[hosts->ht_master]->hd_mtu);     /* Buffer Overrun */  /* Null Pointer Dereference (ID: 22044.28712) */
 1072                 (void)sprintf(buf + strlen(buf), " %d %s",   /* Null Pointer Dereference (ID: 22043.28711) */
 1073                                 ((hp->hd_hostpart & tidhmask) >> (ffs(tidhmask) - 1)),
 1074                                 inadport_hex(&hp->hd_sad));
 1075                 pkstr(mp2, buf);
 1076                 PVM_FREE(buf);
 1077  
 1078                 /* default WIN32 dpath - only if not set manually (a la dx=) */ 
 1079                 if (!(hp->hd_dpath)){
 1080                 len = strlen( winpvmdpath ) + 1 
 1081                         + strlen( (hp->hd_sopts && !strcmp(hp->hd_sopts, "ms") 
 1082                                         ? "-S" : "-s") ) + 1 
 1083                         + 2 + 16 + 1 
 1084                         + 2 + strlen( hp->hd_name ) + 1 
 1085                         + 5 * ( 16 + 1 );
 1086                 buf = TALLOC( len, char, "hdallwin" );
 1087                 (void)sprintf(buf, "%s %s -d0x%x -n%s %d %s %d",
 1088                                 winpvmdpath,
 1089                                 (hp->hd_sopts && !strcmp(hp->hd_sopts, "ms") 
 1090                                         ? "-S" : "-s"),
 1091                                 pvmdebmask,
 1092                                 hp->hd_name,
 1093                                 hosts->ht_master,
 1094                                 inadport_hex( 
 1095                                         &hosts->ht_hosts[hosts->ht_master]->hd_sad),
 1096                                 hosts->ht_hosts[hosts->ht_master]->hd_mtu);   /* Null Pointer Dereference (ID: 22044.28710) */
 1097                 (void)sprintf(buf + strlen(buf), " %d %s",   /* Null Pointer Dereference (ID: 22043.28709) */
 1098                                 ((hp->hd_hostpart & tidhmask) >> (ffs(tidhmask) - 1)),
 1099                                 inadport_hex(&hp->hd_sad));
 1100                 pkstr(mp2, buf);
 1101                 PVM_FREE(buf);
 1102                 }
 1103                 /* be sure to pack SOMETHING, dammit */ 
 1104                 else 
 1105                         pkstr(mp2, "");
 1106  
 1107                 /* Include VMID (If Any) */ 
 1108                 if (hp->hd_vmid)
 1109                         pkstr(mp2, hp->hd_vmid);
 1110                 else if (vmid = getenv("PVM_VMID"))
 1111                         pkstr(mp2, vmid);
 1112                 /* be sure to pack SOMETHING, dammit */ 
 1113                 else 
 1114                         pkstr(mp2, "");
Preconditions
&$unknown_342593 >= 3
&$unknown_342603 >= 1
hosts->ht_last >= 2
((char*)$unknown_342607)[36] = 109
strlen(((char*)&$unknown_342607)[36]) = 2
((char*)&$unknown_342599)[116] != 0
((char*)&$unknown_342607)[16] = 0
((char*)&$unknown_342607)[20] = 0
((char*)&$unknown_342607)[48] = 0
busyadding = 0
filehosts = 0
numfrags != 0
numpmsgs != 0
$input_12 >= 0
$input_33356 >= 0
$input_33372 >= 0
$input_8476 >= 0
$input_8500 >= 0
Postconditions
freefrags.fr_link->fr_link->fr_rlink' = freefrags.fr_link->fr_rlink
freepmsgs.m_link->m_link->m_rlink' = freepmsgs.m_link->m_rlink
freefrags.fr_link->fr_max' = 0
freefrags.fr_link->fr_len' = 0
freefrags.fr_link->fr_u.ref' = 1
freefrags.fr_link->fr_u.dab' = 1
freefrags.fr_link->fr_u.spr' = 0
freefrags.fr_link->fr_rlink' = freefrags.fr_link
freefrags.fr_link->fr_rip' = 0
freefrags.fr_link->fr_buf' = 0
freefrags.fr_link->fr_dat' = 0
freefrags.fr_link->fr_rlink->fr_link' = freefrags.fr_link->fr_link
freepmsgs.m_link->m_rlink->m_link' = freepmsgs.m_link->m_link
freefrags.fr_link->fr_link' = freefrags.fr_link
__x' = 2130706433
atnewline' = 1
buf' = &$heap_29377
strlen(&buf[0])' = 17
buf[17]' = 0
busyadding' = 1
count' = &$unknown_342593
he' = &$heap_29371
bytes_after(&$heap_29358)' = 48
$heap_29358' is allocated by malloc
$heap_29358' is allocated
bytes_before(&$heap_29358)' = 0
((char*)&$heap_29358)[16]' = 0
((char*)&$heap_29358)[36]' = rmp
((char*)&$heap_29358)[40]' = 0
((char*)&$heap_29358)[44]' = &$heap_29359
((char*)&$heap_29358)[12]' = 3
$heap_29359' = &$unknown_342593
bytes_after(&$heap_29359)' = 8
$heap_29359' is allocated by malloc
$heap_29359' is allocated
bytes_before(&$heap_29359)' = 0
((char*)&$heap_29359)[4]' = &$heap_29360
$heap_29360' = 0
bytes_after(&$heap_29360)' = 4 * &$unknown_342593
$heap_29360' is allocated by malloc
$heap_29360' is allocated
bytes_before(&$heap_29360)' = 0
bytes_after(&$heap_29362)' = 120
$heap_29362' is allocated by malloc
$heap_29362' is allocated
bytes_before(&$heap_29362)' = 0
((char*)&$heap_29362)[16]' = 0
((char*)&$heap_29362)[20]' = 0
((char*)&$heap_29362)[8]' = 0
((char*)&$heap_29362)[116]' = 0
((char*)&$heap_29362)[12]' = 0
$heap_29363' = 1
bytes_after(&$heap_29363)' = 124
$heap_29363' is allocated by malloc
bytes_before(&$heap_29363)' = 0
((char*)&$heap_29363)[56]' = 2
((char*)&$heap_29363)[72]' = 1
((char*)&$heap_29363)[76]' = 1
((char*)&$heap_29363)[80]' = &$heap_29362
((char*)&$heap_29363)[84]' = &$heap_29364
((char*)&$heap_29363)[92]' = &$heap_29365
((char*)&$heap_29363)[100]' = 1
((char*)&$heap_29363)[112]' = 0
$heap_29364' = &$heap_29364
bytes_after(&$heap_29364)' = 120
$heap_29364' is allocated by malloc
$heap_29364' is allocated
bytes_before(&$heap_29364)' = 0
((char*)&$heap_29364)[16]' = 0
((char*)&$heap_29364)[20]' = 0
((char*)&$heap_29364)[4]' = &$heap_29364
((char*)&$heap_29364)[8]' = 0
((char*)&$heap_29364)[116]' = 0
((char*)&$heap_29364)[12]' = 0
bytes_after(&$heap_29365)' = 120
$heap_29365' is allocated by malloc
$heap_29365' is allocated
bytes_before(&$heap_29365)' = 0
((char*)&$heap_29365)[16]' = 0
((char*)&$heap_29365)[20]' = 0
((char*)&$heap_29365)[8]' = 0
((char*)&$heap_29365)[116]' = 0
((char*)&$heap_29365)[12]' = 0
$heap_29367' = $input_444
bytes_after(&$heap_29367)' = $input_12 + 1
$heap_29367' is allocated by malloc
$heap_29367' is a non-heap object
bytes_before(&$heap_29367)' = 0
strlen(&$heap_29367)' = $input_12
$heap_29368' = $input_8484
bytes_after(&$heap_29368)' = $input_8476 + 1
$heap_29368' is allocated by malloc
$heap_29368' is a non-heap object
bytes_before(&$heap_29368)' = 0
strlen(&$heap_29368)' = $input_8476
$heap_29369' = $input_8508
bytes_after(&$heap_29369)' = $input_8500 + 1
$heap_29369' is allocated by malloc
$heap_29369' is a non-heap object
bytes_before(&$heap_29369)' = 0
strlen(&$heap_29369)' = $input_8500
$heap_29370' = &$heap_29369
$heap_29370' is a non-heap object
bytes_before(&$heap_29370)' = 0
$heap_29371' = &$heap_29367
bytes_after(&$heap_29371)' = 1024
$heap_29371' is a non-heap object
bytes_before(&$heap_29371)' = 0
((char*)&$heap_29371)[16]' = &$heap_29370
((char*)&$heap_29371)[4]' = &$heap_29372
$heap_29372' = &$heap_29368
$heap_29372' is a non-heap object
bytes_before(&$heap_29372)' = 0
bytes_after(&$heap_29373)' = 4 * &$unknown_342603
$heap_29373' is allocated by malloc
$heap_29373' is freed
bytes_before(&$heap_29373)' = 0
$heap_29374' = $input_33364
bytes_after(&$heap_29374)' = $input_33356 + 1
$heap_29374' is allocated by malloc
$heap_29374' is a non-heap object
bytes_before(&$heap_29374)' = 0
strlen(&$heap_29374)' = $input_33356
$heap_29375' = $input_33380
bytes_after(&$heap_29375)' = $input_33372 + 1
$heap_29375' is allocated by malloc
$heap_29375' is a non-heap object
bytes_before(&$heap_29375)' = 0
strlen(&$heap_29375)' = $input_33372
bytes_after(&$heap_29376)' = strlen(((char*)&$unknown_342607)[116]) + 1
$heap_29376' is allocated by malloc
$heap_29376' is freed
bytes_before(&$heap_29376)' = 0
strlen(&$heap_29376)' = strlen(((char*)&$unknown_342607)[116])
$heap_29377' is allocated by malloc
$heap_29377' is allocated
bytes_before(&$heap_29377)' = 0
hh' = 0
hp' = &$unknown_342607
hp2' = 0
i' = &$unknown_342593 - 2
last_rv' = &$heap_29371
len' >= 0
maxhostid' >= 3
maxhostid' >= &$unknown_342593
mp2' = freepmsgs.m_link
ngood' = 0
ntid' = 0
numfrags' = numfrags - 1
numpmsgs' = numpmsgs - 1
pvmdpath' = &$heap_29374
tids' = &$heap_29373
tmbuf.tm_sec' = &$unknown_342604
winpvmdpath' = &$heap_29375
wp' = &$heap_29358
wxp' = &$heap_29359




Change Warning 107.28713 : Buffer Overrun

Priority:
State:
Finding:
Owner:
Note: