fix: correct qcow2 streaming conversion to device#3
Merged
Conversation
The previous change introduced two critical bugs: 1. Used a local `qemuCmd` variable instead of assigning to `cmd`, leaving `cmd` nil and causing a nil-pointer dereference at the logging and execution lines below the switch. 2. Even with the variable name corrected, `cmd.CombinedOutput()` overrides any prior `cmd.Stdout` assignment, so the device file redirect was silently discarded and no data would reach the volume. Fix by: - Assigning directly to `cmd` in the qcow2 case. - Detecting whether stdout has been redirected after the switch and using `cmd.Run()` + a separate stderr buffer in that path, leaving `cmd.CombinedOutput()` for the raw/dd path. - Using a checked defer for `deviceFile.Close()`. - Adding the required `//nolint:gosec,noctx` annotation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
qcow2case assigned to a localqemuCmdvariable instead ofcmd, leavingcmdnil. The logging (cmd.Args) and execution (cmd.CombinedOutput()) lines below the switch would panic at runtime.cmd.CombinedOutput()unconditionally sets bothStdoutandStderr, silently overriding thecmd.Stdout = deviceFileredirect — no data would reach the LVM volume.noctx: Missing//nolint:gosec,noctxon the newexec.Commandcall.errcheck:defer deviceFile.Close()did not check the error return.Fix
cmdin theqcow2case (not a local variable).cmd.Stdout != nilto choose the execution path:cmd.Run()with a separatebytes.Bufferoncmd.Stderrso stdout continues flowing to the device file and stderr is still captured for error reporting.cmd.CombinedOutput().deferclosure fordeviceFile.Close().//nolint:gosec,noctxannotation.Test plan
go build ./...passesgo test ./...passes (all packages)golangci-lint run ./internal/lvm/...reports 0 issues