fix(transcoders): return error on short onion/onion3 input instead of panicking#289
fix(transcoders): return error on short onion/onion3 input instead of panicking#289SAY-5 wants to merge 2 commits into
Conversation
… panicking Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
Great fix for var TranscoderPort = NewTranscoderFromFunctions(portStB, portBtS, nil) // nil = no validator
func portBtS(b []byte) (string, error) {
i := binary.BigEndian.Uint16(b) // assumes len(b) >= 2, no guard
return strconv.FormatUint(uint64(i), 10), nil
}In isolation So this is not a reachable panic today, but it is a consistency and defense-in-depth gap. Every other fixed-size transcoder either guards internally (e.g. Suggested change: func portBtS(b []byte) (string, error) {
if len(b) < 2 {
return "", fmt.Errorf("port: byte slice too short: %d bytes, want 2", len(b))
}
i := binary.BigEndian.Uint16(b)
return strconv.FormatUint(uint64(i), 10), nil
}
func portValidate(b []byte) error {
if len(b) != 2 {
return fmt.Errorf("port: invalid length: %d bytes, want 2", len(b))
}
return nil
}
var TranscoderPort = NewTranscoderFromFunctions(portStB, portBtS, portValidate)Discovery : Zorya concolic executor Found while auditing the full Three SAT states were produced in under 90 seconds:
The decisive witness is For full disclosure: the finding is the missing guard itself; reachability is bounded by |
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
Thanks for the thorough audit. Pushed 3aac990 mirroring the suggestion: portBtS gets a len < 2 guard returning an error rather than panicking, portValidate enforces len == 2, and TranscoderPort now registers it instead of nil. Test covers nil/1-byte BytesToString, wrong-length Validate, and the 2-byte happy path. |
The
onionBtSandonion3BtStranscoders index their input at fixed offsets without first checkinglen(b). The fixed-sizeCast/validateComponentpaths happen to validate the length, but the transcoders are exported (TranscoderOnion/TranscoderOnion3) so direct callers — or any future code path that reachesBytesToStringbefore validation — see aslice bounds out of rangepanic on short input. Mirror the existingonionValidate/onion3Validatelength checks at the top of each transcoder and return an error instead.Closes #288