@@ -1615,6 +1615,12 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
1615
1615
size_t readsize ;
1616
1616
size_t toread ;
1617
1617
int fseekres ;
1618
+ int8_t found_mi = 0 ;
1619
+ int8_t found_pl = 0 ;
1620
+ int8_t found_fdl = 0 ;
1621
+ int8_t found_il = 0 ;
1622
+ int8_t found_ul = 0 ;
1623
+ int8_t found_ev = 0 ;
1618
1624
1619
1625
//
1620
1626
// Read the section header block
@@ -1651,6 +1657,8 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
1651
1657
{
1652
1658
case MI_BLOCK_TYPE :
1653
1659
case MI_BLOCK_TYPE_INT :
1660
+ found_mi = 1 ;
1661
+
1654
1662
if (scap_read_machine_info (handle , f , bh .block_total_length - sizeof (block_header ) - 4 ) != SCAP_SUCCESS )
1655
1663
{
1656
1664
return SCAP_FAILURE ;
@@ -1660,27 +1668,33 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
1660
1668
case PL_BLOCK_TYPE_V2 :
1661
1669
case PL_BLOCK_TYPE_V1_INT :
1662
1670
case PL_BLOCK_TYPE_V2_INT :
1671
+ found_pl = 1 ;
1672
+
1663
1673
if (scap_read_proclist (handle , f , bh .block_total_length - sizeof (block_header ) - 4 , bh .block_type ) != SCAP_SUCCESS )
1664
1674
{
1665
1675
return SCAP_FAILURE ;
1666
1676
}
1667
1677
break ;
1668
1678
case FDL_BLOCK_TYPE :
1669
1679
case FDL_BLOCK_TYPE_INT :
1680
+ found_fdl = 1 ;
1681
+
1670
1682
if (scap_read_fdlist (handle , f , bh .block_total_length - sizeof (block_header ) - 4 ) != SCAP_SUCCESS )
1671
1683
{
1672
1684
return SCAP_FAILURE ;
1673
1685
}
1674
1686
break ;
1675
1687
case EV_BLOCK_TYPE :
1676
1688
case EV_BLOCK_TYPE_INT :
1689
+ found_ev = 1 ;
1690
+
1677
1691
//
1678
1692
// We're done with the metadata headers. Rewind the file position so we are aligned to start reading the events.
1679
1693
//
1680
1694
fseekres = gzseek (f , (long )0 - sizeof (bh ), SEEK_CUR );
1681
1695
if (fseekres != -1 )
1682
1696
{
1683
- return SCAP_SUCCESS ;
1697
+ break ;
1684
1698
}
1685
1699
else
1686
1700
{
@@ -1689,13 +1703,17 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
1689
1703
}
1690
1704
case IL_BLOCK_TYPE :
1691
1705
case IL_BLOCK_TYPE_INT :
1706
+ found_il = 1 ;
1707
+
1692
1708
if (scap_read_iflist (handle , f , bh .block_total_length - sizeof (block_header ) - 4 ) != SCAP_SUCCESS )
1693
1709
{
1694
1710
return SCAP_FAILURE ;
1695
1711
}
1696
1712
break ;
1697
1713
case UL_BLOCK_TYPE :
1698
1714
case UL_BLOCK_TYPE_INT :
1715
+ found_ul = 1 ;
1716
+
1699
1717
if (scap_read_userlist (handle , f , bh .block_total_length - sizeof (block_header ) - 4 ) != SCAP_SUCCESS )
1700
1718
{
1701
1719
return SCAP_FAILURE ;
@@ -1717,6 +1735,11 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
1717
1735
break ;
1718
1736
}
1719
1737
1738
+ if (found_ev )
1739
+ {
1740
+ break ;
1741
+ }
1742
+
1720
1743
//
1721
1744
// Read and validate the trailer
1722
1745
//
@@ -1732,6 +1755,41 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
1732
1755
}
1733
1756
}
1734
1757
1758
+ if (!found_mi )
1759
+ {
1760
+ snprintf (handle -> m_lasterr , SCAP_LASTERR_SIZE , "corrupted input file. Can't find machine info block." );
1761
+ ASSERT (false);
1762
+ return SCAP_FAILURE ;
1763
+ }
1764
+
1765
+ if (!found_ul )
1766
+ {
1767
+ snprintf (handle -> m_lasterr , SCAP_LASTERR_SIZE , "corrupted input file. Can't find user list block." );
1768
+ ASSERT (false);
1769
+ return SCAP_FAILURE ;
1770
+ }
1771
+
1772
+ if (!found_il )
1773
+ {
1774
+ snprintf (handle -> m_lasterr , SCAP_LASTERR_SIZE , "corrupted input file. Can't find interface list block." );
1775
+ ASSERT (false);
1776
+ return SCAP_FAILURE ;
1777
+ }
1778
+
1779
+ if (!found_fdl )
1780
+ {
1781
+ snprintf (handle -> m_lasterr , SCAP_LASTERR_SIZE , "corrupted input file. Can't find file descriptor list block." );
1782
+ ASSERT (false);
1783
+ return SCAP_FAILURE ;
1784
+ }
1785
+
1786
+ if (!found_pl )
1787
+ {
1788
+ snprintf (handle -> m_lasterr , SCAP_LASTERR_SIZE , "corrupted input file. Can't find process list block." );
1789
+ ASSERT (false);
1790
+ return SCAP_FAILURE ;
1791
+ }
1792
+
1735
1793
return SCAP_SUCCESS ;
1736
1794
}
1737
1795
0 commit comments