Text  |   XML   |   Visible Warnings:

pvm3.4.6 : pvm3.4.6 analysis 2 : Null Pointer Dereference  at pvmd.c:5139

Categories: LANG.MEM.NPD CWE:476
Warning ID: 254.28891
Procedure: mksocs
Trace: view
Modified: Thu Nov 26 11:28:23 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/pvmd.c
   Enter mksocs
 4834 mksocs() 
 4835 {
 4836         struct hostd *hp = hosts->ht_hosts[hosts->ht_local];   /* Buffer Overrun (ID: 22077.28906) */  /* Buffer Underrun (ID: 22076.28905) */
 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: 249.28886) */
 4902  
 4903         if ( cc == -1 ) {
 4904                 pvmlogperror("mksocs() bind netsock");
 4905                 return 1;
 4906         }
 4907  
 4908         oslen = sizeof(hp->hd_sad);   /* Useless Assignment (ID: 248.28885) */
 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;   /* Null Pointer Dereference (ID: 22078.28907) */
 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: 247.28884) */
 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);   /* Buffer Overrun (ID: 256.28893) */
 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: 255.28892) */
 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);   /* File System Race Condition (ID: 253.28890) */
 5137                         return 1;
 5138                 }
true5139                 loclsnam = STRALLOC(sfn);     /* Null Pointer Dereference */
Preconditions
$input_12 <= 97
$input_12 = $input_53244 - 30
$input_12 >= 0
$input_53244 <= 127
$input_53244 >= 30
td = 0
Postconditions
(*hosts->ht_hosts)->hd_sad.sin_family' = &$unknown_705352
(*hosts->ht_hosts)->hd_sad.sin_port' = 0
__x' = 0
((char*)&$unknown_705350)[56]' = &$unknown_705351
strlen(&buf[0])' = $input_12 + 17
buf[0]' is accessed by path name
cc' = $input_53244
d' = &$heap_81033 - 4096
errno' != 0
f' = f + 1
$heap_81028' is allocated by open
$heap_81028' is allocated
$heap_81029' is allocated by open
$heap_81029' is allocated
$heap_81030' is allocated by open
$heap_81030' is allocated
$heap_81031' = $input_444
bytes_after(&$heap_81031)' = $input_12 + 1
$heap_81031' is allocated by malloc
$heap_81031' is a non-heap object
bytes_before(&$heap_81031)' = 0
strlen(&$heap_81031)' = $input_12
$heap_81032' = 0
bytes_after(&$heap_81032)' = $input_12 + 31
$heap_81032' is allocated by malloc
$heap_81032' is allocated
bytes_before(&$heap_81032)' = 0
strlen(&$heap_81032)' = $input_12 + 30
tocttou($heap_81032)' = tocttou(spath)
$heap_81033' is allocated by open
$heap_81033' is allocated
hp' = &$unknown_705350
hp0' = *hosts->ht_hosts
loclsock' = &$heap_81030 - 4096
loclspath' = &$heap_81032
netsock' = &$heap_81028 - 4096
oslen' = 110
p' = &spath[0]
ppnetsock' = &$heap_81029 - 4096
sfn' = &buf[0]
spath[0]' = 0
strlen(&spath[0])' = $input_12 + 30
td' = &$heap_81031
tmpp' = 0
uns.sun_family' = 1
strlen(&uns.sun_family)' = $input_12 + 32
uns.sun_path[0]' = 0
tocttou(uns.sun_path)' = tocttou(spath)




Change Warning 254.28891 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: