Skip to content

Commit

Permalink
fix(libscap): send a consistent length when reading scap files
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Guerra <[email protected]>

Co-authored-by: Federico Di Pierro <[email protected]>
Co-authored-by: Andrea Terzolo <[email protected]>
  • Loading branch information
3 people authored and poiana committed Apr 29, 2024
1 parent 76ffbde commit 32183d4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions userspace/libscap/engine/savefile/scap_savefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,12 @@ static int32_t scap_read_proclist(scap_reader_t* r, uint32_t block_length, uint3
readsize = r->read(r, tinfo.args, stlen);
CHECK_READ_SIZE_ERR(readsize, stlen, error);

// the string is not null-terminated on file
tinfo.args[stlen] = 0;
// the string is sometimes not null-terminated on file
if(stlen > 0 && tinfo.args[stlen - 1] != '\0')
{
tinfo.args[stlen] = '\0';
stlen++;
}
tinfo.args_len = stlen;

subreadsize += readsize;
Expand Down Expand Up @@ -478,8 +482,12 @@ static int32_t scap_read_proclist(scap_reader_t* r, uint32_t block_length, uint3
readsize = r->read(r, tinfo.env, stlen);
CHECK_READ_SIZE_ERR(readsize, stlen, error);

// the string is not null-terminated on file
tinfo.env[stlen] = 0;
// the string is sometimes not null-terminated on file
if(stlen > 0 && tinfo.env[stlen - 1] != '\0')
{
tinfo.env[stlen] = '\0';
stlen++;
}
tinfo.env_len = stlen;

subreadsize += readsize;
Expand Down

0 comments on commit 32183d4

Please sign in to comment.