Skip to content

Fix panic in DecodeMessageWithFDs on read error - #437

Merged
guelfey merged 1 commit into
godbus:masterfrom
kolyshkin:fix-align-panic
Sep 24, 2026
Merged

guelfey merged 1 commit into
godbus:masterfrom
kolyshkin:fix-align-panic

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

The decoder reports read errors by panicking, and those panics are only recovered inside (*decoder).Decode. DecodeMessageWithFDs calls dec.align(8) directly to skip the padding before the message body, so if the underlying reader fails at that point (e.g. the connection is closed concurrently), the panic is not recovered and crashes the program.

Observed in CI as a TestTcpNonceConnection failure (https://github.com/godbus/dbus/actions/runs/35775562848/job/106907758461):

panic: read tcp [::1]:44936->[::1]:41623: use of closed network connection
github.com/godbus/dbus/v5.(*decoder).read2buf(...)
	decoder.go:96
github.com/godbus/dbus/v5.(*decoder).align(...)
	decoder.go:50
github.com/godbus/dbus/v5.DecodeMessageWithFDs(...)
	message.go:182

Skip the padding explicitly and return the read error instead.

The decoder reports read errors by panicking, and those panics are only
recovered inside (*decoder).Decode. DecodeMessageWithFDs calls
dec.align(8) directly to skip the padding before the message body, so
if the underlying reader fails at that point (e.g. the connection is
closed concurrently), the panic is not recovered and crashes the
program.

This was observed in CI as a TestTcpNonceConnection failure:

  panic: read tcp [::1]:44936->[::1]:41623: use of closed network connection
  ...
  github.com/godbus/dbus/v5.(*decoder).align(...)
  	decoder.go:50
  github.com/godbus/dbus/v5.DecodeMessageWithFDs(...)
  	message.go:182

Skip the padding explicitly and return the read error instead.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@guelfey
guelfey merged commit fa096b7 into godbus:master Sep 24, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants