Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sliceInitialLength] false positive: should allow truncation in append #27

Open
seiyab opened this issue Apr 8, 2024 · 1 comment
Open

Comments

@seiyab
Copy link
Owner

seiyab commented Apr 8, 2024

Some programmer truncates slice on append.
Following code is reported though this doesn't cause unintended preceding zero values.

https://github.com/ethereum/go-ethereum/blob/3c75c64e6bbf64f842c6f725a595713262c2f8fe/accounts/usbwallet/ledger.go#L501-L507

	chunk := make([]byte, 64)
	space := len(chunk) - len(header)

	for i := 0; len(apdu) > 0; i++ {
		// Construct the new message to stream
		chunk = append(chunk[:0], header...)
		binary.BigEndian.PutUint16(chunk[3:], uint16(i))
@seiyab
Copy link
Owner Author

seiyab commented Apr 9, 2024

https://github.com/ethereum/go-ethereum/blob/34aac1d7562bf141fe6da1d4f3cdea8819e7b23b/internal/cmdtest/test_cmd.go#L127-L135

func (tt *TestCmd) matchExactOutput(want []byte) error {
	buf := make([]byte, len(want))
	n := 0
	tt.withKillTimeout(func() { n, _ = io.ReadFull(tt.stdout, buf) })
	buf = buf[:n]
	if n < len(want) || !bytes.Equal(buf, want) {
		// Grab any additional buffered output in case of mismatch
		// because it might help with debugging.
		buf = append(buf, make([]byte, tt.stdout.Buffered())...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant