aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/pss/api.go
diff options
context:
space:
mode:
authorlash <nolash@users.noreply.github.com>2018-12-18 22:23:32 +0800
committerAnton Evangelatov <anton.evangelatov@gmail.com>2018-12-18 22:23:32 +0800
commitb01cfce36276379a95deb1001a6f1b6a048609de (patch)
treea0a604810266ba8c8a28982e6dfd582afa09fd84 /swarm/pss/api.go
parentde4265fa028f2b0eb96a21e295028e0d19426adb (diff)
downloadgo-tangerine-b01cfce36276379a95deb1001a6f1b6a048609de.tar
go-tangerine-b01cfce36276379a95deb1001a6f1b6a048609de.tar.gz
go-tangerine-b01cfce36276379a95deb1001a6f1b6a048609de.tar.bz2
go-tangerine-b01cfce36276379a95deb1001a6f1b6a048609de.tar.lz
go-tangerine-b01cfce36276379a95deb1001a6f1b6a048609de.tar.xz
go-tangerine-b01cfce36276379a95deb1001a6f1b6a048609de.tar.zst
go-tangerine-b01cfce36276379a95deb1001a6f1b6a048609de.zip
swarm/pss: Reduce input vulnerabilities (#18304)
Diffstat (limited to 'swarm/pss/api.go')
-rw-r--r--swarm/pss/api.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/swarm/pss/api.go b/swarm/pss/api.go
index 587382d72..4556d7b7c 100644
--- a/swarm/pss/api.go
+++ b/swarm/pss/api.go
@@ -92,7 +92,7 @@ func (pssapi *API) Receive(ctx context.Context, topic Topic, raw bool, prox bool
}
func (pssapi *API) GetAddress(topic Topic, asymmetric bool, key string) (PssAddress, error) {
- var addr *PssAddress
+ var addr PssAddress
if asymmetric {
peer, ok := pssapi.Pss.pubKeyPool[key][topic]
if !ok {
@@ -107,7 +107,7 @@ func (pssapi *API) GetAddress(topic Topic, asymmetric bool, key string) (PssAddr
addr = peer.address
}
- return *addr, nil
+ return addr, nil
}
// Retrieves the node's base address in hex form
@@ -128,7 +128,7 @@ func (pssapi *API) SetPeerPublicKey(pubkey hexutil.Bytes, topic Topic, addr PssA
if err != nil {
return fmt.Errorf("Cannot unmarshal pubkey: %x", pubkey)
}
- err = pssapi.Pss.SetPeerPublicKey(pk, topic, &addr)
+ err = pssapi.Pss.SetPeerPublicKey(pk, topic, addr)
if err != nil {
return fmt.Errorf("Invalid key: %x", pk)
}
@@ -141,11 +141,11 @@ func (pssapi *API) GetSymmetricKey(symkeyid string) (hexutil.Bytes, error) {
}
func (pssapi *API) GetSymmetricAddressHint(topic Topic, symkeyid string) (PssAddress, error) {
- return *pssapi.Pss.symKeyPool[symkeyid][topic].address, nil
+ return pssapi.Pss.symKeyPool[symkeyid][topic].address, nil
}
func (pssapi *API) GetAsymmetricAddressHint(topic Topic, pubkeyid string) (PssAddress, error) {
- return *pssapi.Pss.pubKeyPool[pubkeyid][topic].address, nil
+ return pssapi.Pss.pubKeyPool[pubkeyid][topic].address, nil
}
func (pssapi *API) StringToTopic(topicstring string) (Topic, error) {
@@ -157,14 +157,23 @@ func (pssapi *API) StringToTopic(topicstring string) (Topic, error) {
}
func (pssapi *API) SendAsym(pubkeyhex string, topic Topic, msg hexutil.Bytes) error {
+ if err := validateMsg(msg); err != nil {
+ return err
+ }
return pssapi.Pss.SendAsym(pubkeyhex, topic, msg[:])
}
func (pssapi *API) SendSym(symkeyhex string, topic Topic, msg hexutil.Bytes) error {
+ if err := validateMsg(msg); err != nil {
+ return err
+ }
return pssapi.Pss.SendSym(symkeyhex, topic, msg[:])
}
func (pssapi *API) SendRaw(addr hexutil.Bytes, topic Topic, msg hexutil.Bytes) error {
+ if err := validateMsg(msg); err != nil {
+ return err
+ }
return pssapi.Pss.SendRaw(PssAddress(addr), topic, msg[:])
}
@@ -177,3 +186,10 @@ func (pssapi *API) GetPeerTopics(pubkeyhex string) ([]Topic, error) {
func (pssapi *API) GetPeerAddress(pubkeyhex string, topic Topic) (PssAddress, error) {
return pssapi.Pss.getPeerAddress(pubkeyhex, topic)
}
+
+func validateMsg(msg []byte) error {
+ if len(msg) == 0 {
+ return errors.New("invalid message length")
+ }
+ return nil
+}