From 5bfc9c7eedd3c28dc4524ee7c658cd44da250891 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Sun, 20 Oct 2013 12:50:31 -0400 Subject: [PATCH] Remove possible nil pointer dereferences. Results from FetchTxByShaList must each be checked for a nil Err and a non-nil Tx. Fix this issue in two places where these conditions were not being checked. --- rpcserver.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 20fdc3c0..bea7f8a4 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -859,15 +859,18 @@ func jsonWSRead(walletNotification chan []byte, replychan chan *btcjson.Reply, b return err } txList := s.server.db.FetchTxByShaList(txShaList) - for j := range txList { - for _, txout := range txList[j].Tx.TxOut { + for _, txReply := range txList { + if txReply.Err != nil || txReply.Tx == nil { + continue + } + for _, txout := range txReply.Tx.TxOut { _, txaddrhash, err := btcscript.ScriptToAddrHash(txout.PkScript) if err != nil { return err } if !bytes.Equal(addrhash, txaddrhash) { reply := btcjson.Reply{ - Result: txList[j].Sha, + Result: txReply.Sha, Error: nil, Id: &message.Id, } @@ -1253,9 +1256,11 @@ func (s *rpcServer) NotifyNewTxListeners(db btcdb.Db, block *btcutil.Block) { return } txList := db.FetchTxByShaList(txShaList) - for _, tx := range txList { - go s.newBlockNotifyCheckTxIn(tx.Tx.TxIn) - go s.newBlockNotifyCheckTxOut(db, block, tx) + for _, txReply := range txList { + if txReply.Err == nil && txReply.Tx != nil { + go s.newBlockNotifyCheckTxIn(txReply.Tx.TxIn) + go s.newBlockNotifyCheckTxOut(db, block, txReply) + } } }