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

conn: generate error reply in more cases when trying to send invalid … #397

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dbus
import (
"context"
"errors"
"fmt"
"io"
"os"
"strings"
Expand Down Expand Up @@ -500,15 +501,26 @@ func (conn *Conn) sendMessageAndIfClosed(msg *Message, ifClosed func()) error {
return err
}

func isEncodingError(err error) bool {
switch err.(type) {
case FormatError:
return true
case InvalidMessageError:
return true
}
return false
}

func (conn *Conn) handleSendError(msg *Message, err error) {
if msg.Type == TypeMethodCall {
conn.calls.handleSendError(msg, err)
} else if msg.Type == TypeMethodReply {
if _, ok := err.(FormatError); ok {
if isEncodingError(err) {
// Make sure that the caller gets some kind of error response if
// the application code tried to respond, but the resulting message
// was malformed in the end
conn.sendError(err, msg.Headers[FieldDestination].value.(string), msg.Headers[FieldReplySerial].value.(uint32))
returnedErr := fmt.Errorf("destination tried to respond with invalid message (%w)", err)
conn.sendError(returnedErr, msg.Headers[FieldDestination].value.(string), msg.Headers[FieldReplySerial].value.(uint32))
}
}
conn.serialGen.RetireSerial(msg.serial)
Expand Down
Loading