From 612ad7da2770a344c5618c0d594afaa6217f4766 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Tue, 19 Aug 2025 14:52:28 -0300 Subject: [PATCH] multi: fix non-constant input of fmt.Errorf Fixed multiple cases in which a non-constact string variable was used as a format string for fmt.Errorf. --- chanacceptor/rpcacceptor.go | 2 +- channeldb/migration_01_to_11/zpay32/bech32.go | 3 ++- macaroons/constraints.go | 7 ++++--- rpcserver.go | 2 +- zpay32/bech32.go | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/chanacceptor/rpcacceptor.go b/chanacceptor/rpcacceptor.go index 2b30dedc0..aff8c3dc7 100644 --- a/chanacceptor/rpcacceptor.go +++ b/chanacceptor/rpcacceptor.go @@ -548,7 +548,7 @@ func (r *RPCAcceptor) validateAcceptorResponse(dustLimit btcutil.Amount, // If we reject the channel, and have a custom error, then we use it. case haveCustomError: - return false, fmt.Errorf(req.Error), nil, nil + return false, fmt.Errorf("%s", req.Error), nil, nil // Otherwise, we have rejected the channel with no custom error, so we // just use a generic error to fail the channel. diff --git a/channeldb/migration_01_to_11/zpay32/bech32.go b/channeldb/migration_01_to_11/zpay32/bech32.go index cb1714e48..f32e856cf 100644 --- a/channeldb/migration_01_to_11/zpay32/bech32.go +++ b/channeldb/migration_01_to_11/zpay32/bech32.go @@ -76,7 +76,8 @@ func decodeBech32(bech string) (string, []byte, error) { moreInfo = fmt.Sprintf("Expected %v, got %v.", expected, checksum) } - return "", nil, fmt.Errorf("checksum failed. " + moreInfo) + + return "", nil, fmt.Errorf("checksum failed. %s", moreInfo) } // We exclude the last 6 bytes, which is the checksum. diff --git a/macaroons/constraints.go b/macaroons/constraints.go index 231fd1a46..5716e9eb3 100644 --- a/macaroons/constraints.go +++ b/macaroons/constraints.go @@ -136,7 +136,8 @@ func IPLockChecker() (string, checkers.Func) { // check. pr, ok := peer.FromContext(ctx) if !ok { - return fmt.Errorf("unable to get peer info from context") + return fmt.Errorf("unable to get peer info from " + + "context") } peerAddr, _, err := net.SplitHostPort(pr.Addr.String()) if err != nil { @@ -144,8 +145,8 @@ func IPLockChecker() (string, checkers.Func) { } if !net.ParseIP(arg).Equal(net.ParseIP(peerAddr)) { - msg := "macaroon locked to different IP address" - return fmt.Errorf(msg) + return fmt.Errorf("macaroon locked to different IP " + + "address") } return nil } diff --git a/rpcserver.go b/rpcserver.go index 7add21579..ba787a28f 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -7986,7 +7986,7 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context, errMsg := "cannot set both FeeRate and FeeRatePpm at the " + "same time" - return nil, status.Errorf(codes.InvalidArgument, errMsg) + return nil, status.Errorf(codes.InvalidArgument, "%v", errMsg) // If the request is using fee_rate. case req.FeeRate != 0: diff --git a/zpay32/bech32.go b/zpay32/bech32.go index cb1714e48..f32e856cf 100644 --- a/zpay32/bech32.go +++ b/zpay32/bech32.go @@ -76,7 +76,8 @@ func decodeBech32(bech string) (string, []byte, error) { moreInfo = fmt.Sprintf("Expected %v, got %v.", expected, checksum) } - return "", nil, fmt.Errorf("checksum failed. " + moreInfo) + + return "", nil, fmt.Errorf("checksum failed. %s", moreInfo) } // We exclude the last 6 bytes, which is the checksum.