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

services/horizon: Pass through nil ExtraSigners to avoid nil pointer deref #4349

Merged
merged 6 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func formatUint32(u *xdr.Uint32) null.Int {
}

func formatSigners(s []xdr.SignerKey) pq.StringArray {
if s == nil {
return nil
}

Comment on lines +252 to +255
Copy link
Member

@leighmcculloch leighmcculloch Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this should have no material effect on the XDR because a nil var length array in XDR is a zero length array. There is no distinction between them, unless we've optionalized the array with a pointer in the XDR, which we didn't for extraSigners.

SignerKey extraSigners<2>;

signers := make([]string, len(s))
for i, key := range s {
signers[i] = key.Address()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package integration

import (
"bytes"
"encoding/base64"
"fmt"
"strconv"
"sync"
Expand All @@ -9,9 +11,11 @@ import (

sdk "github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
"github.com/stellar/go/protocols/horizon"
"github.com/stellar/go/services/horizon/internal/test/integration"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -286,7 +290,6 @@ func TestTransactionPreconditionsMinSequenceNumberLedgerGap(t *testing.T) {
}

func buildTXParams(master *keypair.Full, masterAccount txnbuild.Account, txSequence int64) txnbuild.TransactionParams {

return txnbuild.TransactionParams{
SourceAccount: &txnbuild.SimpleAccount{
AccountID: masterAccount.GetAccountID(),
Expand Down Expand Up @@ -334,3 +337,64 @@ func TestTransactionPreconditionsAccountV3Fields(t *testing.T) {
tt.Equal(uint32(tx.Ledger), account.SequenceLedger)
tt.Equal(strconv.FormatInt(tx.LedgerCloseTime.Unix(), 10), account.SequenceTime)
}

// TestTransactionWithoutPreconditions ensures that Horizon doesn't break when
// we have a PRECOND_NONE type transaction (which is not possible to submit
// through SDKs, but is absolutely still possible).
func TestTransactionWithoutPreconditions(t *testing.T) {
tt := assert.New(t)
itest := integration.NewTest(t, integration.Config{})
if itest.GetEffectiveProtocolVersion() < 19 {
t.Skip("Can't run with protocol < 19")
}

master := itest.Master()
masterAccount := itest.MasterAccount()
seqNum, err := masterAccount.GetSequenceNumber()
tt.NoError(err)

account := xdr.MuxedAccount{}
tt.NoError(account.SetEd25519Address(master.Address()))

payment := txnbuild.Payment{ // dummy op
Destination: master.Address(),
Amount: "1000",
Asset: txnbuild.NativeAsset{},
}
paymentOp, err := payment.BuildXDR()
tt.NoError(err)

envelope := xdr.TransactionEnvelope{
Type: xdr.EnvelopeTypeEnvelopeTypeTx,
V1: &xdr.TransactionV1Envelope{
Tx: xdr.Transaction{
SourceAccount: account,
Fee: xdr.Uint32(1000),
SeqNum: xdr.SequenceNumber(seqNum + 1),
Operations: []xdr.Operation{paymentOp},
Cond: xdr.Preconditions{
Type: xdr.PreconditionTypePrecondNone,
},
},
Signatures: nil,
},
}

// Taken from txnbuild.concatSignatures
h, err := network.HashTransactionInEnvelope(envelope,
integration.StandaloneNetworkPassphrase)
tt.NoError(err)

sig, err := master.SignDecorated(h[:])
tt.NoError(err)

// taken from txnbuild.marshallBinary
var txBytes bytes.Buffer
envelope.V1.Signatures = []xdr.DecoratedSignature{sig}
_, err = xdr.Marshal(&txBytes, envelope)
tt.NoError(err)
b64 := base64.StdEncoding.EncodeToString(txBytes.Bytes())

_, err = itest.Client().SubmitTransactionXDR(b64)
tt.NoError(err)
Shaptic marked this conversation as resolved.
Show resolved Hide resolved
}