Skip to content

Commit 1d9fdd6

Browse files
committed
Fix use of unsanitised string in Errorf
If the error message returned by the server contained a `%` character, `Errorf` would attempt to interpolate it, causing a panic.
1 parent ede9ffd commit 1d9fdd6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

spec/matrixerror.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package spec
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
)
2021

@@ -63,7 +64,7 @@ func (e MatrixError) Error() string {
6364
}
6465

6566
func (e MatrixError) Unwrap() error {
66-
return fmt.Errorf(e.Err)
67+
return errors.New(e.Err)
6768
}
6869

6970
// InternalServerError
@@ -231,7 +232,7 @@ func (e IncompatibleRoomVersionError) Error() string {
231232
}
232233

233234
func (e IncompatibleRoomVersionError) Unwrap() error {
234-
return fmt.Errorf(e.Err)
235+
return errors.New(e.Err)
235236
}
236237

237238
// IncompatibleRoomVersion is an error which is returned when the client

tokens/tokens_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ func serializationTestError(err error) string {
6161
func TestSerialization(t *testing.T) {
6262
fakeToken, err := GenerateLoginToken(validTokenOp)
6363
if err != nil {
64-
t.Errorf(serializationTestError(err))
64+
t.Errorf("%s", serializationTestError(err))
6565
}
6666

6767
fakeMacaroon, err := deSerializeMacaroon(fakeToken)
6868
if err != nil {
69-
t.Errorf(serializationTestError(err))
69+
t.Errorf("%s", serializationTestError(err))
7070
}
7171

7272
sameFakeToken, err := serializeMacaroon(fakeMacaroon)
7373
if err != nil {
74-
t.Errorf(serializationTestError(err))
74+
t.Errorf("%s", serializationTestError(err))
7575
}
7676

7777
if sameFakeToken != fakeToken {

0 commit comments

Comments
 (0)