Skip to content

Commit

Permalink
Merge pull request #2323 from mavlink/pr-sonar-fixes-2
Browse files Browse the repository at this point in the history
core: prevent all potential use after stack scope
  • Loading branch information
julianoes authored Jun 2, 2024
2 parents 68f777a + 107eb03 commit 11f569b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/mavsdk/core/inflate_lzma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ static bool decompress(lzma_stream* strm, const char* inname, FILE* infile, FILE

if (fwrite(outbuf, 1, write_size, outfile) != write_size) {
fprintf(stderr, "Write error: %s\n", strerror(errno));
strm->next_in = nullptr;
strm->avail_in = 0;
strm->next_out = nullptr;
strm->avail_out = 0;
return false;
}

Expand All @@ -156,8 +160,13 @@ static bool decompress(lzma_stream* strm, const char* inname, FILE* infile, FILE
// everything has gone well or that when you aren't
// getting more output it must have successfully
// decoded everything.
if (ret == LZMA_STREAM_END)
if (ret == LZMA_STREAM_END) {
strm->next_in = nullptr;
strm->avail_in = 0;
strm->next_out = nullptr;
strm->avail_out = 0;
return true;
}

// It's not LZMA_OK nor LZMA_STREAM_END,
// so it must be an error code. See lzma/base.h
Expand Down Expand Up @@ -225,6 +234,11 @@ static bool decompress(lzma_stream* strm, const char* inname, FILE* infile, FILE
inname,
msg,
ret);

strm->next_in = nullptr;
strm->avail_in = 0;
strm->next_out = nullptr;
strm->avail_out = 0;
return false;
}
}
Expand Down

0 comments on commit 11f569b

Please sign in to comment.