HomeFreeBSD

Address theoretical uninitialized variable usage in zstream

Description

Address theoretical uninitialized variable usage in zstream

Coverity has long complained about the checksum being uninitialized if
an END record is processed before its BEGIN record. This should not
happen, but there was no code to check for it. I had left this unfixed
since it was a low priority issue, but then
9f4ede63d23be4f43ba8dd0ca42c6a773a8eaa8d added another instance of this.

I am making an effort to "hold the line" to keep new coverity defect
reports from going unaddressed, so I find myself forced to fix this much
earlier than I had originally planned to address it.

The solution is to maintain a counter and a flag. Then use VERIFY
statements to verify the following runtime constraints:

  • Every record either has a corresponding BEGIN record, is a BEGIN record or is the end of stream END record for replication streams.
  • BEGIN records cannot be nested. i.e. There must be an END record before another BEGIN record may be seen.

Failure to meet these constraints will cause the program to exit.

This is sufficient to ensure that the checksum is never accessed when
uninitialized.

Reported-by: Coverity (CID 1524578)
Reported-by: Coverity (CID 1524633)
Reported-by: Coverity (CID 1527295)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Damian Szuberski <szuberskidamian@gmail.com>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14176

Details

Provenance
Richard Yao <richard.yao@alumni.stonybrook.edu>Authored on Dec 12 2022, 6:40 PM
GitHub <noreply@github.com>Committed on Dec 12 2022, 6:40 PM
Parents
rG786ff6a6cb33: initramfs: Fix legacy mountpoint rootfs
Branches
Unknown
Tags
Unknown

Event Timeline

GitHub <noreply@github.com> committed rGd31a7cb4fa59: Address theoretical uninitialized variable usage in zstream (authored by Richard Yao <richard.yao@alumni.stonybrook.edu>).Dec 12 2022, 6:40 PM