Skip to content

Commit

Permalink
Make GetFailureMsgData format non-printable error messages
Browse files Browse the repository at this point in the history
Some lightning implementations will send non-printable data in error
messages. For instance outdated versions of lnd will do this:

lightningnetwork/lnd@ff37b71

Whereas these are the error codes (sent as single-byte error messages):

https://github.com/lightningnetwork/lnd/blob/9b1ecbd3fa3fd93a6d95a5f71921c73777340760/lnwire/error.go#L12

These errors need to be printed as bytes when displayed to the user,
rather than interpretted as strings. Error.GetFailureMsgData will now
checks whether an error message is printable before returning the
message as a string and, if it's not, returns a string containing the
hex-encoded binary data in the error.
  • Loading branch information
canndrew committed Apr 21, 2020
1 parent 8395778 commit 6f88df3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/DotNetLightning.Core/Serialize/Msgs/Msgs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,15 @@ type ErrorMessage =
ls.WriteWithLen(this.Data)

member this.GetFailureMsgData() =
System.Text.ASCIIEncoding.ASCII.GetString(this.Data)
let isPrintableAscii =
not <| Array.exists (fun asciiByte -> asciiByte < 32uy) this.Data
if isPrintableAscii then
System.Text.ASCIIEncoding.ASCII.GetString(this.Data)
else
Array.fold
(fun msg (asciiByte: byte) -> sprintf "%s %02x" msg asciiByte)
"<error contains non-printable binary data>:"
this.Data

and WhichChannel =
| SpecificChannel of ChannelId
Expand Down

0 comments on commit 6f88df3

Please sign in to comment.