Text  |   XML   |   Visible Warnings:

pvm3.4.6 : pvm3.4.6 analysis 2 : Null Pointer Dereference  at ddpro.c:1071

Categories: LANG.MEM.NPD CWE:476
Warning ID: 22044.28712
Similar Warnings: 22044.28710
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
 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: 22059.28730) */
 895         wxp->w_hosts = TALLOC(count, struct hostd *, "waiv");   /* Integer Overflow of Allocation Size (ID: 22058.28729) */
 896         BZERO((char*)wxp->w_hosts, count * sizeof(struct hostd *));   /* Null Pointer Dereference (ID: 22057.28728) */
 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: 22054.28725) */
 908  
 909                 } else {
 910  
 911                 /* Set unspecified fields from hostfile if available */ 
 912  
 913                         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                 }
 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: 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  
 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");   /* Integer Overflow of Allocation Size (ID: 22051.28722) */
 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++];   /* Null Pointer Dereference (ID: 22048.28719) */  /* Uninitialized Variable (ID: 22049.28720) */
 1009                 else 
 1010                         hp->hd_err = PvmOutOfRes;
 1011         }
 1012         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  
 1022         wp->wa_mesg = rmp;
 1023  
 1024         /* make request message and send to hoster or pvmd' */ 
 1025  
 1026         mp2 = mesg_new(0);
 1027         mp2->m_wid = wp->wa_wid;   /* Null Pointer Dereference (ID: 22046.28717) */
 1028         pkint(mp2, ngood);
 1029         if (!(pvmdpath = getenv("PVM_DPATH")))
 1030                 pvmdpath = PVMDPATH;
 1031         if (!(winpvmdpath = getenv("PVM_WINDPATH")))
 1032                 winpvmdpath = WINPVMDPATH;
 1033         for (i = 0; i < count; i++) {
 1034                 hp = wxp->w_hosts[i];
 1035                 if (hp->hd_err)
 1036                         continue;
 1037                 pkint(mp2, hp->hd_hostpart);
 1038                 pkstr(mp2, hp->hd_sopts ? hp->hd_sopts : "");
 1039  
 1040                 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                 }
 1048                 else 
 1049                         buf = STRALLOC( (hp->hd_aname 
 1050                                         ? hp->hd_aname : hp->hd_name) );   /* Null Pointer Dereference (ID: 22045.28716) */
 1051                 pkstr(mp2, buf);
 1052                 PVM_FREE(buf);
 1053  
 1054                 /* default unix dpath */ 
 1055                 len = strlen( (hp->hd_dpath ? hp->hd_dpath : pvmdpath) ) + 1 
 1056                         + strlen( (hp->hd_sopts && !strcmp(hp->hd_sopts, "ms") 
 1057                                         ? "-S" : "-s") ) + 1 
 1058                         + 2 + 16 + 1 
 1059                         + 2 + strlen( hp->hd_name ) + 1 
 1060                         + 5 * ( 16 + 1 );
true1061                 buf = TALLOC( len, char, "hdall" );
 1062                 (void)sprintf(buf, "%s %s -d0x%x -n%s %d %s %d",
 1063                                 (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,
 1068                                 hosts->ht_master,
 1069                                 inadport_hex( 
 1070                                         &hosts->ht_hosts[hosts->ht_master]->hd_sad),
buf <= 40951071                                 hosts->ht_hosts[hosts->ht_master]->hd_mtu);     /* Null Pointer Dereference */  /* Buffer Overrun (ID: 107.28713) */
 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_336602 >= 3
&$unknown_336611 <= &$unknown_336602 - 1
&$unknown_336611 >= 2
hosts->ht_hosts[1] != 0
hosts->ht_last >= 2
((char*)$unknown_336616)[36] = 109
strlen(((char*)&$unknown_336616)[36]) = 2
((char*)&$unknown_336608)[116] != 0
((char*)&$unknown_336616)[20] = 0
((char*)&$unknown_336616)[48] = 0
busyadding = 0
filehosts = 0
lasthh = 2
numfrags != 0
numpmsgs != 0
$input_12 >= 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' = 0
strlen(&buf[0])' = 17
buf[17]' = 0
busyadding' = 1
count' = &$unknown_336602
errno' != 0
he' = &$heap_24092
bytes_after(&$heap_24079)' = 48
$heap_24079' is allocated by malloc
$heap_24079' is allocated
bytes_before(&$heap_24079)' = 0
((char*)&$heap_24079)[16]' = 0
((char*)&$heap_24079)[36]' = rmp
((char*)&$heap_24079)[40]' = 0
((char*)&$heap_24079)[44]' = &$heap_24080
((char*)&$heap_24079)[12]' = 3
$heap_24080' = &$unknown_336602
bytes_after(&$heap_24080)' = 8
$heap_24080' is allocated by malloc
$heap_24080' is allocated
bytes_before(&$heap_24080)' = 0
((char*)&$heap_24080)[4]' = &$heap_24081
$heap_24081' = 0
bytes_after(&$heap_24081)' = 4 * &$unknown_336602
$heap_24081' is allocated by malloc
$heap_24081' is allocated
bytes_before(&$heap_24081)' = 0
bytes_after(&$heap_24083)' = 120
$heap_24083' is allocated by malloc
$heap_24083' is allocated
bytes_before(&$heap_24083)' = 0
((char*)&$heap_24083)[16]' = 0
((char*)&$heap_24083)[20]' = 0
((char*)&$heap_24083)[8]' = 0
((char*)&$heap_24083)[116]' = 0
((char*)&$heap_24083)[12]' = 0
$heap_24084' = 1
bytes_after(&$heap_24084)' = 124
$heap_24084' is allocated by malloc
bytes_before(&$heap_24084)' = 0
((char*)&$heap_24084)[56]' = 2
((char*)&$heap_24084)[72]' = 1
((char*)&$heap_24084)[76]' = 1
((char*)&$heap_24084)[80]' = &$heap_24083
((char*)&$heap_24084)[84]' = &$heap_24085
((char*)&$heap_24084)[92]' = &$heap_24086
((char*)&$heap_24084)[100]' = 1
((char*)&$heap_24084)[112]' = 0
$heap_24085' = &$heap_24085
bytes_after(&$heap_24085)' = 120
$heap_24085' is allocated by malloc
$heap_24085' is allocated
bytes_before(&$heap_24085)' = 0
((char*)&$heap_24085)[16]' = 0
((char*)&$heap_24085)[20]' = 0
((char*)&$heap_24085)[4]' = &$heap_24085
((char*)&$heap_24085)[8]' = 0
((char*)&$heap_24085)[116]' = 0
((char*)&$heap_24085)[12]' = 0
bytes_after(&$heap_24086)' = 120
$heap_24086' is allocated by malloc
$heap_24086' is allocated
bytes_before(&$heap_24086)' = 0
((char*)&$heap_24086)[16]' = 0
((char*)&$heap_24086)[20]' = 0
((char*)&$heap_24086)[8]' = 0
((char*)&$heap_24086)[116]' = 0
((char*)&$heap_24086)[12]' = 0
$heap_24088' = $input_444
bytes_after(&$heap_24088)' = $input_12 + 1
$heap_24088' is allocated by malloc
$heap_24088' is a non-heap object
bytes_before(&$heap_24088)' = 0
strlen(&$heap_24088)' = $input_12
$heap_24089' = $input_8484
bytes_after(&$heap_24089)' = $input_8476 + 1
$heap_24089' is allocated by malloc
$heap_24089' is a non-heap object
bytes_before(&$heap_24089)' = 0
strlen(&$heap_24089)' = $input_8476
$heap_24090' = $input_8508
bytes_after(&$heap_24090)' = $input_8500 + 1
$heap_24090' is allocated by malloc
$heap_24090' is a non-heap object
bytes_before(&$heap_24090)' = 0
strlen(&$heap_24090)' = $input_8500
$heap_24091' = &$heap_24090
$heap_24091' is a non-heap object
bytes_before(&$heap_24091)' = 0
$heap_24092' = &$heap_24088
bytes_after(&$heap_24092)' = 1024
$heap_24092' is a non-heap object
bytes_before(&$heap_24092)' = 0
((char*)&$heap_24092)[16]' = &$heap_24091
((char*)&$heap_24092)[4]' = &$heap_24093
$heap_24093' = &$heap_24089
$heap_24093' is a non-heap object
bytes_before(&$heap_24093)' = 0
$heap_24094' is allocated by malloc
$heap_24094' is freed
bytes_before(&$heap_24094)' = 0
hh' = 0
hp' = &$unknown_336616
hp2' = 0
i' = &$unknown_336602 - 2
j' >= 0
last_rv' = &$heap_24092
lasthh' = 2
len' = strlen(((char*)&$unknown_336616)[8]) + 129
maxhostid' >= 3
maxhostid' >= &$unknown_336602
mp2' = freepmsgs.m_link
ngood' = 0
ntid' = 0
numfrags' = numfrags - 1
numpmsgs' = numpmsgs - 1
pvmdpath' = &#string10[0]
tids' = 0
tmbuf.tm_sec' = &$unknown_336613
winpvmdpath' = &#string12[0]
wp' = &$heap_24079
wxp' = &$heap_24080




Change Warning 22044.28712 : Null Pointer Dereference

Because they are very similar, this warning shares annotations with warning 22044.28710.
CodeSonar has selected warning 22044.28710 to represent this group of similar warnings. In order to edit this group, you must edit warning 22044.28710.