]> git.proxmox.com Git - mirror_zfs.git/commit
Address theoretical uninitialized variable usage in zstream
authorRichard Yao <richard.yao@alumni.stonybrook.edu>
Mon, 12 Dec 2022 18:40:05 +0000 (13:40 -0500)
committerGitHub <noreply@github.com>
Mon, 12 Dec 2022 18:40:05 +0000 (10:40 -0800)
commitd31a7cb4fa59c7a2ff39cd091643c18617b601c1
tree7f147b3a9cfde1ad501efca3279b311c26b53bea
parent786ff6a6cb33226b4f4292c7569b9093286f74d9
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
cmd/zstream/zstream_decompress.c
cmd/zstream/zstream_recompress.c
cmd/zstream/zstream_redup.c