Skip to content

Commit

Permalink
Return the actual number of bytes written to through command buffer (#…
Browse files Browse the repository at this point in the history
…287)

The `Write` function returned the number of bytes written to the
internal command response buffer in the simulator. Depending on the
type of command executed against the TPM, this would usually result
in a different number of bytes being written than the original input.

The fix is useful if one wants to wrap the io.ReadWriterCloser
functions with implementations that perform strict checks. An example
is using an io.MultiWriter to capture the bytes sent to the TPM for
debugging purposes, which will fail if the number of bytes written
does not equal the original length of the input bytes.
  • Loading branch information
hslatman authored Mar 14, 2023
1 parent 72f571a commit 9e791b1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func (s *Simulator) Write(commandBuffer []byte) (int, error) {
if err != nil {
return 0, err
}
return s.buf.Write(resp)
// write response to the internal response buffer.
_, _ = s.buf.Write(resp)
return len(commandBuffer), nil
}

// Read gets the response of a command previously issued by calling Write().
Expand Down

0 comments on commit 9e791b1

Please sign in to comment.