Text  |   XML   |   Visible Warnings:

Pvm : Pvm analysis 1 : Null Pointer Dereference  at ddpro.c:1027

Categories: LANG.MEM.NPD CWE:476
Warning ID: 2513.2544
Procedure: addhosts
Trace: View
Modified: Wed Sep 2 12:40:04 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/ddpro.c
   Enter addhosts
 840 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;
 846         struct waitc *wp = 0;
 847         struct waitc_add *wxp = 0;
 848         int i, j;
 849         int count;
 850         int ngood;
 851         int ntid;
 852         struct hostent *he;
 853         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         */ 
 868         if (busyadding) {
 869 /*
 870                 pvmlogerror("addhosts() already adding new hosts\n");
 871 */ 
 872                 pkint(rmp, PvmAlready);
 873                 sendmessage(rmp);
 874                 return 0;
 875         }
 876  
 877         busyadding = 1;
 878  
 879         /* sanity check count */ 
 880  
 881         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  
 890         wp = wait_new(WT_HOSTSTART);
 891         wp->wa_tid = mp->m_src;
 892         wp->wa_dep = mp->m_wid;
 893         wxp = TALLOC(1, struct waitc_add, "waix");
 894         wxp->w_num = count;   /* Null Pointer Dereference (ID: 2522.2553) */
 895         wxp->w_hosts = TALLOC(count, struct hostd *, "waiv");
 896         BZERO((char*)wxp->w_hosts, count * sizeof(struct hostd *));   /* Null Pointer Dereference (ID: 2521.2552) */
 897         wp->wa_spec = (void *)wxp;
 898  
 899         for (i = 0; i < count; i++) {
 900                 hp = hd_new(0);
 901                 wxp->w_hosts[i] = hp;
 902                 if (upkstralloc(mp, &buf)) {
 903                         pvmlogerror("addhosts() bad msg format\n");
 904                         goto bad;
 905                 }
 906                 if (parsehost(buf, hp)) {
 907                         hp->hd_err = PvmBadParam;   /* Null Pointer Dereference (ID: 2518.2549) */
 908  
 909                 } else {
 910  
 911                 /* Set unspecified fields from hostfile if available */ 
 912  
 913                         if (filehosts &&
 914                                         ((hp2 = nametohost(filehosts, hp->hd_name)) 
 915                                         || (hp2 = filehosts->ht_hosts[0])))
 916                                 applydefaults(hp, hp2);
 917                 }
 918                 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  
 926         hp = hosts->ht_hosts[hosts->ht_local];
 927  
 928         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  
 933                 for (i = 0; i < count; i++) {
 934                         hp = wxp->w_hosts[i];
 935                         if (hp->hd_err)
 936                                 continue;
 937                         hp->hd_err = PvmIPLoopback;
 938                 }
 939         }
 940  
 941         /*
 942         * lookup IP addresses  XXX we already have some of them 
 943         */ 
 944  
 945         ngood = 0;
 946         for (i = 0; i < count; i++) {
 947                 hp = wxp->w_hosts[i];
 948                 if (hp->hd_err)
 949                         continue;
 950  
 951                 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,
 953                                         sizeof(struct in_addr));   /* Buffer Overrun (ID: 2517.2548) */
 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  
 967                 if (!(hp->hd_flag & HF_OVERLOAD)) {
 968                         for (hh = hosts->ht_last; hh > 0; hh--)
 969                                 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                                 }
 974                         if (hp->hd_err)
 975                                 continue;
 976  
 977         /* make sure new ones aren't duplicated */ 
 978  
 979                         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                                 }
 985                         if (hp->hd_err)
 986                                 continue;
 987                 }
 988  
 989                 ngood++;
 990         }
 991  
 992         /*
 993         * assign tids  XXX these are unreserved until hosts are added...
 994         */ 
 995  
 996         ntid = ngood;
 997         tids = TALLOC(ngood, int, "xxx");
 998         hostids_new(&ntid, tids);
 999         if (ntid < ngood) {
 1000                 pvmlogerror("addhosts() out of hostids\n");
 1001                 ngood = ntid;
 1002         }
 1003         for (j = i = 0; i < count; i++) {
 1004                 hp = wxp->w_hosts[i];
 1005                 if (hp->hd_err)
 1006                         continue;
 1007                 if (j < ntid)
 1008                         hp->hd_hostpart = tids[j++];   /* Uninitialized Variable (ID: 2514.2545) */
 1009                 else 
 1010                         hp->hd_err = PvmOutOfRes;
 1011         }
 1012         PVM_FREE(tids);   /* Free Null Pointer (ID: 2515.2546) */
 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  
 1022         wp->wa_mesg = rmp;
 1023  
 1024         /* make request message and send to hoster or pvmd' */ 
 1025  
true1026         mp2 = mesg_new(0);
mp2 <= 40951027         mp2->m_wid = wp->wa_wid;     /* Null Pointer Dereference */
Preconditions
&$unknown_320210 >= 2
&$unknown_320213 >= 1
&$unknown_320217 <= hosts->ht_last
&$unknown_320217 >= 2
&$unknown_320220 >= 1
hosts->ht_last >= 2
waitlist->wa_wid >= widbase + 2
((char*)&$unknown_320222)[80] = 0
busyadding = 0
filehosts = 0
$heap_14623 != 0
strlen(&$heap_14623) != 0
lasthh = 1
numpmsgs = 0
widrange <= lastwid
Postconditions
waitlist->wa_rlink' = &$heap_14615
waitlist->wa_rlink->wa_link' = &$heap_14615
__x' = 2130706433
atnewline' = 1
buf' = &$heap_14623
busyadding' = 1
count' = &$unknown_320210
freepmsgs.m_link' = &freepmsgs.m_link
freepmsgs.m_rlink' = &freepmsgs.m_link
ghbn_h_name[0]' = 60
strlen(&ghbn_h_name[0])' = 255
ghbn_h_name[255]' = 0
he' = &stored_hostent.h_name
$heap_14615' = waitlist
bytes_after(&$heap_14615)' = 80
$heap_14615' is allocated by malloc
$heap_14615' is allocated
bytes_before(&$heap_14615)' = 0
((char*)&$heap_14615)[16]' = widbase + 1
((char*)&$heap_14615)[20]' = 3
((char*)&$heap_14615)[24]' = 0
((char*)&$heap_14615)[56]' = $param_2
((char*)&$heap_14615)[64]' = 0
((char*)&$heap_14615)[72]' = &$heap_14616
((char*)&$heap_14615)[8]' = waitlist->wa_rlink
$heap_14616' = &$unknown_320210
bytes_after(&$heap_14616)' = 16
$heap_14616' is allocated by malloc
$heap_14616' is allocated
bytes_before(&$heap_14616)' = 0
((char*)&$heap_14616)[8]' = &$heap_14617
$heap_14617' = 0
bytes_after(&$heap_14617)' = 8 * &$unknown_320210
$heap_14617' is allocated by malloc
$heap_14617' is allocated
bytes_before(&$heap_14617)' = 0
strlen(&$heap_14617)' = 0
$heap_14619' = 1
bytes_after(&$heap_14619)' = 200
$heap_14619' is allocated by malloc
bytes_before(&$heap_14619)' = 0
strlen(&$heap_14619)' = 0
((char*)&$heap_14619)[136]' = &$heap_14622
((char*)&$heap_14619)[152]' = 1
((char*)&$heap_14619)[176]' = 0
((char*)&$heap_14619)[88]' = 2
((char*)&$heap_14619)[104]' = 1
((char*)&$heap_14619)[108]' = 1
((char*)&$heap_14619)[112]' = &$heap_14620
((char*)&$heap_14619)[120]' = &$heap_14621
bytes_after(&$heap_14620)' = 184
$heap_14620' is allocated by malloc
$heap_14620' is allocated
bytes_before(&$heap_14620)' = 0
((char*)&$heap_14620)[16]' = 0
((char*)&$heap_14620)[176]' = 0
((char*)&$heap_14620)[24]' = 0
((char*)&$heap_14620)[32]' = 0
((char*)&$heap_14620)[40]' = 0
bytes_after(&$heap_14621)' = 184
$heap_14621' is allocated by malloc
$heap_14621' is allocated
bytes_before(&$heap_14621)' = 0
((char*)&$heap_14621)[16]' = 0
((char*)&$heap_14621)[176]' = 0
((char*)&$heap_14621)[24]' = 0
((char*)&$heap_14621)[32]' = 0
((char*)&$heap_14621)[40]' = 0
$heap_14622' = &$heap_14622
bytes_after(&$heap_14622)' = 184
$heap_14622' is allocated by malloc
$heap_14622' is allocated
bytes_before(&$heap_14622)' = 0
((char*)&$heap_14622)[16]' = 0
((char*)&$heap_14622)[176]' = 0
((char*)&$heap_14622)[24]' = 0
((char*)&$heap_14622)[32]' = 0
((char*)&$heap_14622)[40]' = 0
((char*)&$heap_14622)[8]' = &$heap_14622
bytes_after(&$heap_14623)' = &$unknown_320213
$heap_14623' is allocated by malloc
$heap_14623' is freed
bytes_before(&$heap_14623)' = 0
bytes_after(&$heap_14624)' = 4 * &$unknown_320220
$heap_14624' is allocated by malloc
$heap_14624' is freed
bytes_before(&$heap_14624)' = 0
hh' = &$unknown_320217 - 1
hp' = &$unknown_320222
hp2' = &$unknown_320218
i' = &$unknown_320210
lasthh' = 1
lastwid' = 1
maxhostid' >= 2
maxhostid' >= &$unknown_320210
mp' = $param_1
mp2' = 0
ngood' = 0
ntid' = 0
rmp' = $param_2
tids' = &$heap_14624
tmbuf.tm_sec' = &$unknown_320221
wp' = &$heap_14615
wxp' = &$heap_14616




Change Warning 2513.2544 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: