Text  |   XML   |   Visible Warnings:

Pvm : Pvm analysis 1 : Null Pointer Dereference  at hoster.c:754

Categories: LANG.MEM.NPD CWE:476
Warning ID: 2483.2511
Similar Warnings: 2483.2512
Procedure: pl_startup
Trace: View
Modified: Wed Sep 2 12:39:48 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/hoster.c
   Enter pl_startup
 480 pl_startup(num, hostlist) 
 481         int num;
 482         struct hst **hostlist;
 483 {
 484         int nxth = 0;                                           /* next host in list to start */ 
 485         struct slot *slact = 0;                         /* active list of slots */ 
 486         struct hst *hp;
 487         struct slot *sp, *sp2;
 488         struct timeval tnow;
 489         struct timeval tout;
 490 #ifdef FDSETNOTSTRUCT 
 491         fd_set rfds;                                            /* emx headers */ 
 492 #else 
 493         struct fd_set rfds; 
 494 #endif 
 495         int nfds;
 496         int i;
 497         int n;
 498         char *p;
 499  
 500         /* init slot free list */ 
 501  
 502         slfree = &slots[RSHNPLL+1];
 503         slfree->s_link = slfree->s_rlink = slfree;
 504         slact = &slots[RSHNPLL];
 505         slact->s_link = slact->s_rlink = slact;
 506         for (i = RSHNPLL; i-- > 0; ) {
 507                 LISTPUTAFTER(slfree, &slots[i], s_link, s_rlink);
 508         }
 509  
 510         /*
 511         * keep at this until all hosts in table are completed 
 512         */ 
 513  
 514         for (; ; ) {
 515  
 516                 /*
 517                 * if empty slots, start on new hosts 
 518                 */ 
 519  
 520                 for (; ; ) {
 521  
 522                         /* find a host for slot */ 
 523  
 524                         if (slfree->s_link != slfree && nxth < num)
 525                                 hp = hostlist[nxth++];
 526                         else 
 527                                 break;
 528  
 529                         sp = slfree->s_link;
 530                         LISTDELETE(sp, s_link, s_rlink);
 531                         sp->s_hst = hp;
 532                         sp->s_len = 0;
 533                         sp->s_elen = 0;
 534                         if (pvmdebmask & PDMSTARTUP) {
 535                                 pvmlogprintf("pl_startup() trying %s\n", hp->h_name);
 536                         }
 537                         phase1(sp);
 538                         if (hp->h_result) {
 539                                 /* error or fully started (manual startup) */ 
 540  
 541                                 if (pvmdebmask & PDMSTARTUP) {
 542                                         pvmlogprintf( 
 543                                         "pl_startup() got result \"%s\" for %s phase1()\n",
 544                                                 hp->h_result, hp->h_name);
 545                                 }
 546  
 547                                 LISTPUTBEFORE(slfree, sp, s_link, s_rlink);
 548  
 549                         } else {
 550                                 /* partially started */ 
 551  
 552                                 LISTPUTBEFORE(slact, sp, s_link, s_rlink);
 553                                 pvmgetclock(&sp->s_bail);
 554                                 tout.tv_sec = RSHTIMEOUT;
 555                                 tout.tv_usec = 0;
 556                                 TVXADDY(&sp->s_bail, &sp->s_bail, &tout);
 557                         }
 558                 }
 559  
 560                 /* if no hosts in progress, we are finished */ 
 561  
 562                 if (slact->s_link == slact)
 563                         break;
 564  
 565                 /*
 566                 * until next timeout, get output from any slot 
 567                 */ 
 568  
 569                 FD_ZERO(&rfds);
 570                 nfds = 0;
 571                 TVCLEAR(&tout);
 572                 pvmgetclock(&tnow);
 573                 for (sp = slact->s_link; sp != slact; sp = sp->s_link) {
 574                         if (TVXLTY(&sp->s_bail, &tnow)) {
 575                                 pvmlogprintf("pl_startup() giving up on host %s after %d secs\n",
 576                                                 sp->s_hst->h_name, RSHTIMEOUT);
 577                                 sp->s_hst->h_result = STRALLOC("PvmCantStart");   /* Null Pointer Dereference (ID: 2483.2512) */
 578                                 sp2 = sp->s_rlink;
 579                                 close_slot(sp);
 580                                 sp = sp2;
 581                                 continue;
 582                         }
 583  
 584                         if (!TVISSET(&tout) || TVXLTY(&sp->s_bail, &tout))
 585                                 tout = sp->s_bail;
 586                         if (sp->s_rfd >= 0)
 587                                 FD_SET(sp->s_rfd, &rfds);
 588                         if (sp->s_rfd > nfds)
 589                                 nfds = sp->s_rfd;
 590                         if (sp->s_efd >= 0)
 591                                 FD_SET(sp->s_efd, &rfds);
 592                         if (sp->s_efd > nfds)
 593                                 nfds = sp->s_efd;
 594                 }
 595  
 596                 if (slact->s_link == slact)
 597                         break;
 598  
 599                 nfds++;
 600  
 601                 if (TVXLTY(&tnow, &tout)) {
 602                         TVXSUBY(&tout, &tout, &tnow);
 603                 } else {
 604                         TVCLEAR(&tout);
 605                 }
 606                 if (pvmdebmask & PDMSTARTUP) {
 607                         pvmlogprintf("pl_startup() select timeout is %d.%06d\n",
 608                                         tout.tv_sec, tout.tv_usec);
 609                 }
 610                 if ((n = select(nfds,
 611 #ifdef  FDSETISINT 
 612                                 (int *)&rfds, (int *)0, (int *)0, 
 613 #else 
 614                                 (fd_set *)&rfds, (fd_set *)0, (fd_set *)0,
 615 #endif 
 616                                 &tout)) == -1) {
 617                         if (errno != EINTR) {
 618                                 pvmlogperror("pl_startup() select");
 619                                 pvmbailout(0);
 620                         }
 621                 }
 622                 if (pvmdebmask & PDMSTARTUP) {
 623                         pvmlogprintf("pl_startup() select returns %d\n", n);
 624                 }
 625                 if (n < 1) {
 626                         if (n == -1 && errno != EINTR) {
 627                                 pvmlogperror("pl_startup() select");
 628                                 pvmbailout(0);  /* XXX this is too harsh */ 
 629                         }
 630                         continue;
 631                 }
 632  
 633                 /*
 634                 * check for response on stdout or stderr of any slave.
 635                 */ 
 636  
 637                 for (sp = slact->s_link; sp != slact; sp = sp->s_link) {
 638  
 639                         /*
 640                         * stderr ready.  log output with remote's host name.
 641                         */ 
 642                         if (sp->s_efd >= 0 && FD_ISSET(sp->s_efd, &rfds)) {
 643                                 n = read(sp->s_efd, sp->s_ebuf + sp->s_elen,
 644                                                 sizeof(sp->s_ebuf) - sp->s_elen - 1);
 645                                 if (n > 0) {
 646                                         sp->s_elen += n;
 647                                         sp->s_ebuf[sp->s_elen] = 0;
 648                                         while (p = CINDEX(sp->s_ebuf, '\n')) {
 649                                                 *p = 0;
 650                                                 pvmlogprintf("stderr@%s: %s\n",
 651                                                                 sp->s_hst->h_name, sp->s_ebuf);
 652                                                 p++;
 653                                                 sp->s_elen -= p - sp->s_ebuf;
 654                                                 if (sp->s_elen > 0) {
 655                                                         BCOPY(p, sp->s_ebuf, sp->s_elen);
 656                                                         sp->s_ebuf[sp->s_elen] = 0;
 657                                                 }
 658                                         }
 659                                         if (sp->s_elen == sizeof(sp->s_ebuf) - 1) {
 660                                                 pvmlogprintf("stderr@%s: %s\n",
 661                                                                 sp->s_hst->h_name, sp->s_ebuf);
 662                                                 sp->s_elen = 0;
 663                                         }
 664  
 665                                 } else {
 666                                         if (sp->s_elen > 0) {
 667                                                 pvmlogprintf("stderr@%s: %s\n",
 668                                                                 sp->s_hst->h_name, sp->s_ebuf);
 669                                                 sp->s_elen = 0;
 670                                         }
 671                                         (void)close(sp->s_efd);
 672                                         sp->s_efd = -1;
 673                                 }
 674                         }
 675  
 676                         /*
 677                         * stdout ready.
 678                         * look for a complete line starting with "ddpro".
 679                         */ 
 680                         if (sp->s_rfd >= 0 && FD_ISSET(sp->s_rfd, &rfds)) {
 681                                 n = read(sp->s_rfd, sp->s_buf + sp->s_len,
 682                                                 sizeof(sp->s_buf) - sp->s_len - 1);
 683                                 if (n > 0) {
 684                                         sp->s_len += n;
 685                                         sp->s_buf[sp->s_len] = 0;
 686                                         while (p = CINDEX(sp->s_buf, '\n')) {
 687                                                 *p = 0;
 688                                                 if (!strncmp(sp->s_buf, "ddpro", 5)) {
 689                                                         if (pvmdebmask & PDMSTARTUP) {
 690                                                                 pvmlogprintf("stdout@%s: %s\n",
 691                                                                                 sp->s_hst->h_name, sp->s_buf);
 692                                                         }
 693                                                         sp->s_hst->h_result = STRALLOC(sp->s_buf);
   ...
 703                                                                 sp->s_buf[sp->s_len] = 0;
 704                                                         }
 705                                                 }
 706                                         }
 707                                         if (sp->s_len == sizeof(sp->s_buf) - 1) {
 708                                                 pvmlogprintf("stdout@%s: %s\n",
 709                                                                 sp->s_hst->h_name, sp->s_buf);
 710                                                 sp->s_len = 0;
 711                                         }
 712  
 713                                 } else {
 714                                         if (sp->s_len > 0) {
 715                                                 pvmlogprintf("stdout@%s: %s\n",
 716                                                                 sp->s_hst->h_name, sp->s_buf);
 717                                                 sp->s_len = 0;
 718                                         }
 719                                         if (n) {
 720                                                 pvmlogprintf("stdout@%s",
 721                                                                 sp->s_hst->h_name);
 722                                         } else {
 723                                                 pvmlogprintf("stdout@%s: EOF\n",
 724                                                                 sp->s_hst->h_name);
 725                                         }
 726                                         if (sp->s_elen > 0) {
 727                                                 pvmlogprintf("stderr@%s: %s\n",
 728                                                                 sp->s_hst->h_name, sp->s_ebuf);
 729                                                 sp->s_elen = 0;
 730                                         }
 731  
 732                                         /* before failing, check for alternate WIN32 cmd */ 
 733                                         if (sp->s_hst->h_wincmd) {
 734                                                 if (pvmdebmask & PDMSTARTUP) {
 735                                                         pvmlogprintf( 
 736                                                                 "pl_startup() re-trying %s as WIN32\n",
 737                                                                 hp->h_name);
 738                                                 }
 739                                                 /* no need to free h_cmd, we're a pvmd'... */ 
 740                                                 sp->s_hst->h_cmd = sp->s_hst->h_wincmd;
 741                                                 sp->s_hst->h_wincmd = 0;
 742  
 743                                                 phase1(sp);
 744  
 745                                                 if (!(sp->s_hst->h_result)) {
 746                                                         /* partially started */ 
 747                                                         pvmgetclock(&sp->s_bail);
 748                                                         tout.tv_sec = RSHTIMEOUT;
 749                                                         tout.tv_usec = 0;
 750                                                         TVXADDY(&sp->s_bail, &sp->s_bail, &tout);
 751                                                 }
 752  
 753                                         } else {
true754                                                 sp->s_hst->h_result = STRALLOC("PvmCantStart");     /* Null Pointer Dereference */
Preconditions
$param_1 >= 1
&$unknown_104361 >= 1
&slots[0].s_link != &$unknown_104346 - 3456
&slots[0].s_link != &$unknown_104350 - 2880
&slots[0].s_link = $unknown_104350 - 2880
((char*)&((char*)$unknown_104350)[16])[48] = 0
$unknown_104350 >= 6976
((char*)&$unknown_104350)[24] <= -1
((char*)&$unknown_104350)[40] >= 0
((char*)&$unknown_104350)[48] >= 0
$input_12 = &$unknown_104361
$input_12 >= 1
tnow.tv_usec >= 0
Postconditions
((char*)$unknown_104350)[8]' = ((char*)&$unknown_104350)[8]
((char*)&((char*)$unknown_104350)[16])[64]' = &$heap_4129
((char*)$unknown_104350)[8]' = $unknown_104350
__arr' = &rfds.__fds_bits[0]
__i' = 16
((char*)&$unknown_104346)[564]' = 0
((char*)&$unknown_104346)[568]' = 0
$unknown_104350' = &slots[0].s_link + 3456
((char*)&$unknown_104350)[564]' = 0
((char*)&$unknown_104350)[568]' = 0
((char*)&$unknown_104350)[8]' = &$unknown_104353
$unknown_104353' = &$unknown_104350
$heap_4129' = 80
bytes_after(&$heap_4129)' = 13
$heap_4129' is allocated by malloc
$heap_4129' is allocated
bytes_before(&$heap_4129)' = 0
strlen(&$heap_4129)' = 12
hostlist' = $param_2
i' = -1
n' = 0
nfds' = 1
num' = $param_1
nxth' = $param_1
p' = 0
rfds.__fds_bits[15]' = 0
slact' = &slots[0].s_link + 2880
slfree' = &slots[0].s_link + 3456
slots[5].s_link' = &$unknown_104350
slots[6].s_link' = &$unknown_104346
slots[6].s_rlink' = &$unknown_104350
sp' = &$unknown_104350
sp2' = ((char*)&$unknown_104350)[8]
tnow.tv_sec' = 0
tout.tv_sec' = 0
tout.tv_usec' = 0




Change Warning 2483.2511 : Null Pointer Dereference

Because they are very similar, this warning shares annotations with warning 2483.2512.

Priority:
State:
Finding:
Owner:
Note: