From 30ac0eb609bc1d48e8c15ac23cba8598fa27dca6 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Tue, 27 Mar 2018 17:26:08 +0200 Subject: [PATCH] whisper: fix issue in topic list copy (#16381) - Fixes #16271. What was appeneded was a pointer to an object that changes during the iteration. - The topic is allocated as a 4-byte array, fill partial topics with 0s. Partial topics are currently disabled, but would crash as they rely on the presence of byte number 3. --- whisper/whisperv6/api.go | 7 ++++--- whisper/whisperv6/api_test.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go index 96e2b17e7cf0..3f3a082afe97 100644 --- a/whisper/whisperv6/api.go +++ b/whisper/whisperv6/api.go @@ -558,9 +558,10 @@ func (api *PublicWhisperAPI) NewMessageFilter(req Criteria) (string, error) { } if len(req.Topics) > 0 { - topics = make([][]byte, 0, len(req.Topics)) - for _, topic := range req.Topics { - topics = append(topics, topic[:]) + topics = make([][]byte, len(req.Topics)) + for i, topic := range req.Topics { + topics[i] = make([]byte, TopicLength) + copy(topics[i], topic[:]) } } diff --git a/whisper/whisperv6/api_test.go b/whisper/whisperv6/api_test.go index 71101412af32..004a41c9496a 100644 --- a/whisper/whisperv6/api_test.go +++ b/whisper/whisperv6/api_test.go @@ -22,7 +22,7 @@ import ( "testing" "time" - "github.com/NiluPlatform/go-nilu/common" + "github.com/ethereum/go-ethereum/common" set "gopkg.in/fatih/set.v0" )