Text  |   XML   |   Visible Warnings:

pvm3.4.6 : pvm3.4.6 analysis 2 : Null Test After Dereference  at lpvm.c:1742

Categories: LANG.STRUCT.NTAD
Warning ID: 334.29013
Procedure: mxinput
Trace: view
Modified: Thu Nov 26 11:29:34 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     
LineSource
  /kat0/fletcher/SATE/2010/pvm3/src/lpvm.c
  Enter mxinput
1545 mxinput(pcbp, nfr) 
1546         struct ttpcb *pcbp;
1547         int *nfr;                               /* number of frags read */ 
1548 {
1549         int gotem = 0;                  /* num msgs added to pvmrxlist */ 
1550         struct frag *fp;                /* shadows pcbp->tt_rxf */ 
1551         struct frag *fp2;
1552         int n;                                  /* bytes received */ 
1553         int m;                                  /* length of fragment */ 
1554         struct pmsg *rxup;              /* message containing this frag */ 
1555         struct pmsg *hdfrgpile;
1556         char *cp;                               /* gp */ 
1557         int src;
1558         int dst;
1559         int ff;
1560         static int fairprobe = 0;
1561  
1562         *nfr = 0;
1563  
1564  
1565 #if defined(IMA_MPP) 
1566  
1567         /* Messages from Tasks and  Messages from the daemon  are probed 
1568          * fairprobe makes sure that neither interface gets starved.  
1569          * fairprobe is toggled when an EOM is found   
1570         */ 
1571  
1572         switch (fairprobe)
  ...
1584                         if ((fp = pvm_readfrompvmd()) == (struct frag *) NULL)  
1585                                 fp = pvm_readfrompeer();
1586                         break;
1587  
1588         }
1589  
1590         if (!fp)  
1591                 return gotem;   /* didn't read anything */ 
1592  
1593 #else 
1594         if (!pcbp->tt_rxf)
1595                 if (!(pcbp->tt_rxf = fr_new(pvmfrgsiz)))   /* Redundant Condition (ID: 335.29014) */
1596                         return PvmNoMem;   /* Unreachable Computation (ID: 336.29015) */
1597         fp = pcbp->tt_rxf;
1598  
1599         /* read fragment header separately from body */ 
1600  
1601         n = (fp->fr_len < TDFRAGHDR) ? 0 : pvmget32(fp->fr_dat + 8);
1602         n += TDFRAGHDR - fp->fr_len;
1603         if (pvmdebmask & PDMPACKET) {
1604                 pvmlogprintf("mxinput() pcb t%x fr_len=%d fr_dat=+%d n=%d\n",
1605                                 pcbp->tt_tid, fp->fr_len, fp->fr_dat - fp->fr_buf, n);
1606         }
1607 #ifndef WIN32 
1608         n = read(pcbp->tt_fd, fp->fr_dat + fp->fr_len, n);   /* Null Pointer Dereference (ID: 341.29018) */
1609 #else 
1610         n = win32_read_socket( pcbp->tt_fd,fp->fr_dat+fp->fr_len,n); 
1611 #endif 
1612         if (pvmdebmask & PDMPACKET) {
1613                 pvmlogprintf("mxinput() read=%d\n", n);
1614         }
1615  
1616         /* deal with errors and closes */ 
1617  
1618         if (n == -1 &&  
1619 #ifndef WIN32 
1620                         errno != EWOULDBLOCK &&  
1621 #endif 
1622                         errno != EINTR)
1623         {
1624                 if (pvmdebmask & PDMPACKET) {
1625                         pvmlogperror("mxinput() read");
1626                         pvmlogprintf("mxinput() t%x\n", pcbp->tt_tid);
1627                 }
1628                 return PvmSysErr;
1629         }
1630         if (!n) {
1631                 if (pvmdebmask & PDMPACKET) {
1632                         pvmlogprintf("mxinput() t%x read EOF\n", pcbp->tt_tid);
1633                 }
1634                 return -1;
1635         }
1636  
1637         if (n < 1)
1638                 return gotem;
1639         if ((fp->fr_len += n) < TDFRAGHDR)
1640                 return gotem;
1641  
1642         /* realloc buffer if frag won't fit */ 
1643  
1644         m = TDFRAGHDR + pvmget32(fp->fr_dat + 8);
1645         if (fp->fr_len == TDFRAGHDR) {
1646                 if (m > fp->fr_max - (fp->fr_dat - fp->fr_buf)) {
1647                         fp2 = fr_new(m);
1648                         BCOPY(fp->fr_dat, fp2->fr_dat, TDFRAGHDR);
1649                         fp2->fr_len = fp->fr_len;
1650                         fr_unref(fp);
1651                         fp = pcbp->tt_rxf = fp2;
1652                         if (pvmdebmask & PDMPACKET) {
1653                                 pvmlogprintf("mxinput() realloc frag max=%d\n", m);
1654                         }
1655                 }
1656         }
1657  
1658 #endif /* defined (IMA_MPP) */ 
1659          
1660         /* Now get information from the frag header to determine 
1661          * src, destination, length, etc.
1662         */ 
1663 #if !defined(IMA_MPP)
1664         if (fp->fr_len == m)  
1665 #else 
1666         if (fp)  /* got a frag */ 
1667 #endif 
1668         {
1669                 (*nfr)++;
1670 #if !defined (IMA_MPP)
1671                 pcbp->tt_rxf = 0;
1672 #endif 
1673                 cp = fp->fr_dat;
1674                 dst = pvmget32(cp);
1675                 src = pvmget32(cp + 4);
1676                 ff = pvmget8(cp + 12);
1677                 fp->fr_len -= TDFRAGHDR;
1678                 fp->fr_dat += TDFRAGHDR;
1679  
1680                 if (pvmdebmask & PDMPACKET) {
1681                         pvmlogprintf("mxinput() pkt src t%x len %d ff %d\n",
1682                                         src, fp->fr_len, ff);
1683         }
1684  
1685 #if defined(IMA_MPP) 
1686         if (fp -> fr_rip )      /* frag was received inplace */ 
1687         {
1688                 gotem++;
1689                 fr_unref(fp); /* free frag -- mppprecv knows that the msg completed */ 
1690                 return gotem;
1691         }
1692  
1693         hdfrgpile = pvm_mpp_pmsgs(); 
1694 #else 
1695         hdfrgpile = pcbp->tt_rxfrag ;
1696 #endif 
1697         /*
1698         * if start of message, make new umbuf, add to frag pile 
1699         */ 
1700                 if (ff & FFSOM) {
1701                         cp += TDFRAGHDR;
1702                         fp->fr_len -= MSGHDRLEN;
1703                         fp->fr_dat += MSGHDRLEN;
1704                         rxup = umbuf_new();
1705                         rxup->m_enc = pvmget32(cp);   /* Null Pointer Dereference (ID: 338.29017) */
1706                         rxup->m_tag = pvmget32(cp + 4);
1707                         rxup->m_ctx = pvmget32(cp + 8);
1708                         rxup->m_wid = pvmget32(cp + 16);
1709                         rxup->m_crc = pvmget32(cp + 20);
1710                         rxup->m_src = src;
1711                         rxup->m_dst = dst;
1712  
1713                         LISTPUTBEFORE(hdfrgpile, rxup, m_link, m_rlink);
1714  
1715                 } else {
1716                         /* locate frag's message */ 
1717  
1718                         for (rxup = hdfrgpile->m_link; rxup != hdfrgpile;  
1719                                         rxup = rxup->m_link)
1720                                 if (rxup->m_src == src)
1721                                         break;
1722                 }
1723  
1724                 if (rxup == hdfrgpile) {        /* uh oh, no message for it */ 
1725                         pvmlogerror("mxinput() frag with no message\n");
1726                         fr_unref(fp);
1727  
1728                 } else {
1729                         LISTPUTBEFORE(rxup->m_frag, fp, fr_link, fr_rlink);
1730                         rxup->m_len += fp->fr_len;
1731         /*
1732         * if end of message, move to pvmrxlist and count it 
1733         */ 
1734                         if (ff & FFEOM) {
1735 #if defined(IMA_MPP) 
1736                                 fairprobe = (fairprobe ? 0 : 1); 
1737 #endif 
1738                                 LISTDELETE(rxup, m_link, m_rlink);
1739                                 if (pvmdebmask & PDMMESSAGE) {
1740                                         pvmlogprintf( 
1741                                                         "mxinput() src t%x route t%x ctx %d tag %s len %d\n",
1742                                                         rxup->m_src, (pcbp != 0 ? pcbp->tt_tid: -1),      /* Null Test After Dereference */
1743                                                         rxup->m_ctx,
1744                                                         pvmnametag(rxup->m_tag, (int *)0), rxup->m_len);
1745                                 }
1746 #ifdef  MCHECKSUM 
1747                                 if (rxup->m_crc != umbuf_crc(rxup)) {
1748                                         pvmlogprintf(
1749                                         "mxinput() message src t%x route t%x tag %s bad checksum\n",
1750                                                         rxup->m_src, pcbp->tt_tid,
1751                                                         pvmnametag(rxup->m_tag, (int *)0));
1752                                         umbuf_free(rxup);
1753  
1754                                 } else { 
1755 #endif 
1756                                         pmsg_setenc(rxup, rxup->m_enc);
1757                                         mesg_input(rxup);
1758                                         gotem++;
1759 #ifdef  MCHECKSUM 
1760                                 } 
1761 #endif 
1762                         }
1763                 }
1764         }
1765         return gotem;
1766 } 




Change Warning 334.29013 : Null Test After Dereference

Priority:
State:
Finding:
Owner:
Note: