Skip to content

Commit a1877a7

Browse files
Abort, instead of keeping going with a NULL pointer, if key parts of the trace file are missing
1 parent c75c450 commit a1877a7

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

userspace/libscap/scap_savefile.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,12 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
16151615
size_t readsize;
16161616
size_t toread;
16171617
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;
16181624

16191625
//
16201626
// Read the section header block
@@ -1651,6 +1657,8 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
16511657
{
16521658
case MI_BLOCK_TYPE:
16531659
case MI_BLOCK_TYPE_INT:
1660+
found_mi = 1;
1661+
16541662
if(scap_read_machine_info(handle, f, bh.block_total_length - sizeof(block_header) - 4) != SCAP_SUCCESS)
16551663
{
16561664
return SCAP_FAILURE;
@@ -1660,27 +1668,33 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
16601668
case PL_BLOCK_TYPE_V2:
16611669
case PL_BLOCK_TYPE_V1_INT:
16621670
case PL_BLOCK_TYPE_V2_INT:
1671+
found_pl = 1;
1672+
16631673
if(scap_read_proclist(handle, f, bh.block_total_length - sizeof(block_header) - 4, bh.block_type) != SCAP_SUCCESS)
16641674
{
16651675
return SCAP_FAILURE;
16661676
}
16671677
break;
16681678
case FDL_BLOCK_TYPE:
16691679
case FDL_BLOCK_TYPE_INT:
1680+
found_fdl = 1;
1681+
16701682
if(scap_read_fdlist(handle, f, bh.block_total_length - sizeof(block_header) - 4) != SCAP_SUCCESS)
16711683
{
16721684
return SCAP_FAILURE;
16731685
}
16741686
break;
16751687
case EV_BLOCK_TYPE:
16761688
case EV_BLOCK_TYPE_INT:
1689+
found_ev = 1;
1690+
16771691
//
16781692
// We're done with the metadata headers. Rewind the file position so we are aligned to start reading the events.
16791693
//
16801694
fseekres = gzseek(f, (long)0 - sizeof(bh), SEEK_CUR);
16811695
if(fseekres != -1)
16821696
{
1683-
return SCAP_SUCCESS;
1697+
break;
16841698
}
16851699
else
16861700
{
@@ -1689,13 +1703,17 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
16891703
}
16901704
case IL_BLOCK_TYPE:
16911705
case IL_BLOCK_TYPE_INT:
1706+
found_il = 1;
1707+
16921708
if(scap_read_iflist(handle, f, bh.block_total_length - sizeof(block_header) - 4) != SCAP_SUCCESS)
16931709
{
16941710
return SCAP_FAILURE;
16951711
}
16961712
break;
16971713
case UL_BLOCK_TYPE:
16981714
case UL_BLOCK_TYPE_INT:
1715+
found_ul = 1;
1716+
16991717
if(scap_read_userlist(handle, f, bh.block_total_length - sizeof(block_header) - 4) != SCAP_SUCCESS)
17001718
{
17011719
return SCAP_FAILURE;
@@ -1717,6 +1735,11 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
17171735
break;
17181736
}
17191737

1738+
if(found_ev)
1739+
{
1740+
break;
1741+
}
1742+
17201743
//
17211744
// Read and validate the trailer
17221745
//
@@ -1732,6 +1755,41 @@ int32_t scap_read_init(scap_t *handle, gzFile f)
17321755
}
17331756
}
17341757

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+
17351793
return SCAP_SUCCESS;
17361794
}
17371795

0 commit comments

Comments
 (0)