Text  |   XML   |   Visible Warnings:

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

Categories: LANG.MEM.NPD CWE:476
Warning ID: 2512.2543
Procedure: addhosts
Trace: View
Modified: Wed Sep 2 12:40:03 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  
 1026         mp2 = mesg_new(0);
 1027         mp2->m_wid = wp->wa_wid;   /* Null Pointer Dereference (ID: 2513.2544) */
 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: 2511.2542) */
 1047                 }
 1048                 else 
 1049                         buf = STRALLOC( (hp->hd_aname 
true1050                                         ? hp->hd_aname : hp->hd_name) );     /* Null Pointer Dereference */
 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 );
 1061                 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),
 1071                                 hosts->ht_hosts[hosts->ht_master]->hd_mtu);   /* Null Pointer Dereference (ID: 2510.2541) */
 1072                 (void)sprintf(buf + strlen(buf), " %d %s",
 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: 2510.2540) */
 1097                 (void)sprintf(buf + strlen(buf), " %d %s",
 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_316013 >= 3
&$unknown_316020 <= hosts->ht_last
&$unknown_316020 >= 2
&$unknown_316024 = &$unknown_316025 + 136
&$unknown_316024 >= 4232
&$unknown_316028 = 0
hosts->ht_last >= 2
waitlist->wa_wid >= widbase + 2
((char*)&$unknown_316026)[184] != 0
((char*)&$unknown_316026)[24] = 0
((char*)&$unknown_316026)[64] = 0
((char*)&$unknown_316026)[80] = 0
busyadding = 0
filehosts = 0
numpmsgs = 0
widrange <= lastwid
Postconditions
waitlist->wa_rlink' = &$heap_12169
waitlist->wa_rlink->wa_link' = &$heap_12169
((char*)$unknown_316025)[8]' = &$unknown_316024
__x' = 2130706433
$unknown_316024' = &freepmsgs.m_link
((char*)&$unknown_316024)[8]' = ((char*)&$unknown_316025)[8]
busyadding' = 1
count' = &$unknown_316013
freepmsgs.m_link' = &$unknown_316025
freepmsgs.m_rlink' = &$unknown_316025 + 136
ghbn_h_name[0]' = 60
strlen(&ghbn_h_name[0])' = 255
ghbn_h_name[255]' = 0
he' = &stored_hostent.h_name
$heap_12169' = waitlist
bytes_after(&$heap_12169)' = 80
$heap_12169' is allocated by malloc
$heap_12169' is allocated
bytes_before(&$heap_12169)' = 0
((char*)&$heap_12169)[16]' = widbase + 1
((char*)&$heap_12169)[20]' = 3
((char*)&$heap_12169)[24]' = 0
((char*)&$heap_12169)[56]' = $param_2
((char*)&$heap_12169)[64]' = 0
((char*)&$heap_12169)[72]' = &$heap_12170
((char*)&$heap_12169)[8]' = waitlist->wa_rlink
$heap_12170' = &$unknown_316013
bytes_after(&$heap_12170)' = 16
$heap_12170' is allocated by malloc
$heap_12170' is allocated
bytes_before(&$heap_12170)' = 0
((char*)&$heap_12170)[8]' = &$heap_12171
$heap_12171' = 0
bytes_after(&$heap_12171)' = 8 * &$unknown_316013
$heap_12171' is allocated by malloc
$heap_12171' is allocated
bytes_before(&$heap_12171)' = 0
strlen(&$heap_12171)' = 0
$heap_12173' = 1
bytes_after(&$heap_12173)' = 200
$heap_12173' is allocated by malloc
bytes_before(&$heap_12173)' = 0
strlen(&$heap_12173)' = 0
((char*)&$heap_12173)[136]' = &$heap_12176
((char*)&$heap_12173)[152]' = 1
((char*)&$heap_12173)[176]' = 0
((char*)&$heap_12173)[88]' = 2
((char*)&$heap_12173)[104]' = 1
((char*)&$heap_12173)[108]' = 1
((char*)&$heap_12173)[112]' = &$heap_12174
((char*)&$heap_12173)[120]' = &$heap_12175
bytes_after(&$heap_12174)' = 184
$heap_12174' is allocated by malloc
$heap_12174' is allocated
bytes_before(&$heap_12174)' = 0
((char*)&$heap_12174)[16]' = 0
((char*)&$heap_12174)[176]' = 0
((char*)&$heap_12174)[24]' = 0
((char*)&$heap_12174)[32]' = 0
((char*)&$heap_12174)[40]' = 0
bytes_after(&$heap_12175)' = 184
$heap_12175' is allocated by malloc
$heap_12175' is allocated
bytes_before(&$heap_12175)' = 0
((char*)&$heap_12175)[16]' = 0
((char*)&$heap_12175)[176]' = 0
((char*)&$heap_12175)[24]' = 0
((char*)&$heap_12175)[32]' = 0
((char*)&$heap_12175)[40]' = 0
$heap_12176' = &$heap_12176
bytes_after(&$heap_12176)' = 184
$heap_12176' is allocated by malloc
$heap_12176' is allocated
bytes_before(&$heap_12176)' = 0
((char*)&$heap_12176)[16]' = 0
((char*)&$heap_12176)[176]' = 0
((char*)&$heap_12176)[24]' = 0
((char*)&$heap_12176)[32]' = 0
((char*)&$heap_12176)[40]' = 0
((char*)&$heap_12176)[8]' = &$heap_12176
$heap_12178' is allocated by malloc
$heap_12178' is freed
bytes_before(&$heap_12178)' = 0
hh' = &$unknown_316020 - 1
hp' = &$unknown_316026
hp2' = &$unknown_316021
i' = &$unknown_316013 - 2
j' >= 2
lastwid' = 1
maxhostid' >= 3
maxhostid' >= &$unknown_316013
mp' = $param_1
mp2' = &$unknown_316025
ngood' >= 2
ntid' >= 2
numpmsgs' = 49
pvmdpath' = &#string10[0]
rmp' = $param_2
tids' = &$heap_12178
winpvmdpath' = &#string12[0]
wp' = &$heap_12169
wxp' = &$heap_12170




Change Warning 2512.2543 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: