Text  |   XML   |   Visible Warnings:

Pvm : Pvm analysis 1 : Null Pointer Dereference  at pvmd.c:5139

Categories: LANG.MEM.NPD CWE:476
Warning ID: 2664.2709
Procedure: mksocs
Trace: View
Modified: Wed Sep 2 12:42:42 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/pvmd.c
   Enter mksocs
 4834 mksocs() 
 4835 {
 4836         struct hostd *hp = hosts->ht_hosts[hosts->ht_local];   /* Buffer Overrun (ID: 2668.2713) */  /* Buffer Underrun (ID: 2667.2712) */
 4837         struct hostd *hp0 = hosts->ht_hosts[0];
 4838         struct sockaddr_in sin;
 4839         char buf[128];
 4840         char *sfn;
 4841 #ifndef WIN32 
 4842         int d;
 4843 #else 
 4844         HANDLE d;
 4845         int e=0; 
 4846 #endif 
 4847 #ifndef NOSOCKOPT 
   ...
 4865 #endif 
 4866 #ifdef IMA_BEOLIN 
 4867         struct hostent *hostaddr; 
 4868 #endif 
 4869         short tmpp;
 4870  
 4871         /*
 4872         * make pvmd-pvmd socket 
 4873         */ 
 4874  
 4875         if ((netsock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
 4876                 pvmlogperror("mksocs() socket netsock");
 4877                 return 1;
 4878         }
 4879  
 4880         p = getenv("PVMNETSOCKPORT");
 4881  
 4882         tmpp = (p) ? atoi(p) : 0;
 4883  
 4884         hp->hd_sad.sin_port = htons(tmpp);
 4885  
 4886         do 
 4887         {
 4888                 oslen = sizeof(hp->hd_sad);
 4889                 if ((cc=bind(netsock, (struct sockaddr*)&hp->hd_sad, oslen)) 
 4890                                 == -1)
 4891                 {
 4892                         if (p) {
 4893                                 tmpp++;
 4894                                 hp->hd_sad.sin_port = htons(tmpp);
 4895                         } else {
 4896                                 pvmlogperror("mksocs() bind netsock");
 4897                                 return 1;
 4898                         }
 4899                 }
 4900         }
 4901         while ( cc == -1 && p && hp->hd_sad.sin_port < 65535 );   /* Redundant Condition (ID: 2661.2706) */
 4902  
 4903         if ( cc == -1 ) {
 4904                 pvmlogperror("mksocs() bind netsock");
 4905                 return 1;
 4906         }
 4907  
 4908         oslen = sizeof(hp->hd_sad);   /* Useless Assignment (ID: 2659.2704) */
 4909         if (getsockname(netsock, (struct sockaddr*)&hp->hd_sad, &oslen) == -1) {
 4910                 pvmlogperror("mksocs() getsockname netsock");
 4911                 return 1;
 4912         }
 4913  
 4914         /*
 4915         * make pvmd-pvmd' socket 
 4916         */ 
 4917  
 4918         if ((ppnetsock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
 4919                 pvmlogperror("mksocs() socket ppnetsock");
 4920                 return 1;
 4921         }
 4922  
 4923         hp0->hd_sad.sin_port = 0;
 4924         oslen = sizeof(hp0->hd_sad);
 4925         if (bind(ppnetsock, (struct sockaddr*)&hp0->hd_sad, oslen) == -1) {
 4926                 pvmlogperror("mksocs() bind ppnetsock");
 4927                 return 1;
 4928         }
 4929         oslen = sizeof(hp0->hd_sad);   /* Useless Assignment (ID: 2660.2705) */
 4930         if (getsockname(ppnetsock, (struct sockaddr*)&hp0->hd_sad, &oslen) == -1) {
 4931                 pvmlogperror("mksocs() getsockname ppnetsock");
 4932                 return 1;
 4933         }
 4934  
 4935         /*
 4936         * make pvmd-local task socket 
 4937         */ 
 4938  
 4939 #ifdef NOUNIXDOM 
 4940         if ((loclsock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
   ...
 5022         || setsockopt(ppnetsock, SOL_SOCKET, SO_RCVBUF,
 5023                         (char*)&bsz, sizeof(bsz)) == -1) {
 5024                 pvmlogperror("mksocs() setsockopt");
 5025                 return 1;
 5026         }
 5027 #endif /*NOSOCKOPT*/ 
 5028  
 5029         p = inadport_hex(&sin); 
 5030  
 5031 #else /*NOUNIXDOM*/ 
 5032         if ((loclsock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
 5033                 pvmlogperror("mksocs() socket loclsock");
 5034                 return 1;
 5035         }
 5036  
 5037         BZERO((char*)&uns, sizeof(uns));
 5038         uns.sun_family = AF_UNIX;
 5039         spath[0] = 0;
 5040         (void)PVMTMPNAMFUN(spath);
 5041         strcpy(uns.sun_path, spath);
 5042 /*
 5043 XXX len?
 5044 */ 
 5045  
 5046         oslen = sizeof(uns);
 5047         if (bind(loclsock, (struct sockaddr*)&uns, oslen) == -1) {
 5048                 pvmlogperror("mksocs() bind loclsock");
 5049                 return 1;
 5050         }
 5051  
 5052         if (listen(loclsock, SOMAXCONN) == -1) {
 5053                 pvmlogperror("mksocs() listen loclsock");
 5054                 return 1;
 5055         }
 5056  
 5057         loclspath = STRALLOC(spath);   /* Null Pointer Dereference (ID: 2665.2710) */
 5058         p = spath;
 5059  
 5060 #endif /*NOUNIXDOM*/ 
 5061  
 5062         /*
 5063         * make pvmd-local task socket address file 
 5064         */ 
 5065  
 5066         if (!(sfn = pvmdsockfile())) {
 5067                 pvmlogerror("mksocs() pvmdsockfile() failed\n");
 5068                 pvmbailout(0);
 5069         }
 5070  
 5071 #ifndef WIN32 
 5072         if ((d = open(sfn, O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0600)) == -1) {
 5073                 if (errno == EEXIST) {
 5074 #else 
 5075         d = win32_create_file(sfn, CREATE_NEW);
 5076         if ((int) d == -2){
 5077                 /* this code is for WIN95 */ 
 5078                 system_loser_win = TRUE;
 5079                 e = _open(sfn,O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0600);
 5080         }
 5081         if (((int)d == -1) || (e ==-1)) {
 5082                 if (1) {  /* errno == EEXIST */ 
   ...
 5091                         (void)pvmlogprintf( 
 5092                                         "mksocs() %s exists.  pvmd already running?\n", sfn);
 5093                         return 2;
 5094 #endif 
 5095  
 5096                 } else {
 5097                         pvmlogperror(sfn);
 5098                         pvmlogerror("mksocs() can't write address file\n");
 5099                         return 1;
 5100                 }
 5101         } else {
 5102 #ifndef WIN32 
 5103                 cc = write(d, p, strlen(p));
 5104 #else 
 5105                 CloseHandle(d);
 5106                 if (!system_loser_win) {
 5107                         if ((d = (HANDLE) win32_open_file(sfn)) == (HANDLE) -1) {
 5108                                 pvmlogprintf("could not open file %s: %d \n",
 5109                                                 sfn,GetLastError());
 5110                         return 2;
 5111                         }
 5112                         cc = win32_write_file(d,p,strlen(p));
 5113                 } else 
 5114                         /* the win95 case */ 
 5115                         cc = write(e,p,strlen(p)); 
 5116 #endif 
 5117                 if (cc != strlen(p)) {
 5118                         if (cc == -1) {
 5119                                 pvmlogperror(sfn);
 5120                                 pvmlogerror("mksocs() can't write address file\n");
 5121  
 5122                         } else {
 5123                                 (void)pvmlogprintf( 
 5124                                                 "mksocs() aargh, short write on %s: %d\n",
 5125                                                 sfn, cc);
 5126                                 pvmlogerror("mksocs() is the partition full?\n");
 5127                         }
   ...
 5129                         (void)close(d);
 5130 #else 
 5131                         if (d)
 5132                                 CloseHandle(d);
 5133                         if (e)
 5134                                 close(e); 
 5135 #endif 
 5136                         (void)unlink(sfn);
 5137                         return 1;
 5138                 }
true5139                 loclsnam = STRALLOC(sfn);     /* Null Pointer Dereference */
Preconditions
$input_12 >= 0
td = 0
Postconditions
(*hosts->ht_hosts)->hd_sad.sin_family' = &$unknown_789241
(*hosts->ht_hosts)->hd_sad.sin_port' = 0
__v' <= 65534
__x' = $input_9052
((char*)&$unknown_789239)[88]' = &$unknown_789240
((char*)&$unknown_789239)[90]' = __v'
buf[0]' is opened
cc' = 0
d' = &$heap_46074 - 4096
errno' != 0
f' = f + 1
$heap_46069' is allocated by open
$heap_46069' is allocated
((char*)&$heap_46069)[-4096]' is open
((char*)&$heap_46069)[-4096]' is bound
$heap_46070' = $input_60
bytes_after(&$heap_46070)' = $input_12 + 1
$heap_46070' is allocated by malloc
$heap_46070' is a non-heap object
bytes_before(&$heap_46070)' = 0
strlen(&$heap_46070)' = $input_12
$heap_46071' is allocated by open
$heap_46071' is allocated
((char*)&$heap_46071)[-4096]' is open
((char*)&$heap_46071)[-4096]' is bound
$heap_46072' is allocated by open
$heap_46072' is allocated
((char*)&$heap_46072)[-4096]' is open
((char*)&$heap_46072)[-4096]' is listening
bytes_after(&$heap_46073)' = 1
$heap_46073' is allocated by malloc
$heap_46073' is allocated
bytes_before(&$heap_46073)' = 0
strlen(&$heap_46073)' = 0
$heap_46074' is allocated by open
$heap_46074' is allocated
((char*)&$heap_46074)[-4096]' is open
hp' = &$unknown_789239
hp0' = *hosts->ht_hosts
loclsock' = &$heap_46072 - 4096
loclspath' = &$heap_46073
netsock' = &$heap_46069 - 4096
oslen' = 110
p' = &spath[0]
ppnetsock' = &$heap_46071 - 4096
sfn' = &buf[0]
strlen(&spath[0])' = 0
uns.sun_family' = 1
strlen(&uns.sun_family)' = 2
uns.sun_path[0]' = spath[0]'




Change Warning 2664.2709 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: