From 16ae675107c150f3373bc8f6ae0647b27f4f0b4e Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 15 Feb 2015 02:08:08 +0100 Subject: [PATCH 1/5] Unmarshal in to pointer to string --- rpc/args.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpc/args.go b/rpc/args.go index 84b076d4a..12e3103bc 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -43,7 +43,7 @@ type PushTxArgs struct { func (obj *PushTxArgs) UnmarshalJSON(b []byte) (err error) { arg0 := "" - if err = json.Unmarshal(b, arg0); err == nil { + if err = json.Unmarshal(b, &arg0); err == nil { obj.Tx = arg0 return } @@ -82,7 +82,7 @@ type GetStateArgs struct { func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) { arg0 := "" - if err = json.Unmarshal(b, arg0); err == nil { + if err = json.Unmarshal(b, &arg0); err == nil { obj.Address = arg0 return } @@ -114,7 +114,7 @@ type GetTxCountArgs struct { func (obj *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) { arg0 := "" - if err = json.Unmarshal(b, arg0); err == nil { + if err = json.Unmarshal(b, &arg0); err == nil { obj.Address = arg0 return } From b143dad596f4230d74dadd3c5060020bd50ef7f3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 15 Feb 2015 02:09:57 +0100 Subject: [PATCH 2/5] Reference pointer to block instead of pointer to function --- core/chain_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/chain_manager.go b/core/chain_manager.go index 308e958fe..54f1ced8c 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -168,7 +168,7 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block { var root []byte parentHash := ZeroHash256 - if bc.CurrentBlock != nil { + if bc.currentBlock != nil { root = bc.currentBlock.Header().Root parentHash = bc.lastBlockHash } From 09e53367a24025564686af42c8349d2bd05729c3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 15 Feb 2015 02:12:14 +0100 Subject: [PATCH 3/5] Use a mutex write-lock for a write operation --- p2p/server.go | 8 ++++---- rpc/packages.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/p2p/server.go b/p2p/server.go index e510be521..35b584a27 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -436,15 +436,15 @@ func (self *BlacklistMap) Exists(pubkey []byte) (ok bool) { } func (self *BlacklistMap) Put(pubkey []byte) error { - self.lock.RLock() - defer self.lock.RUnlock() + self.lock.Lock() + defer self.lock.Unlock() self.blacklist[string(pubkey)] = true return nil } func (self *BlacklistMap) Delete(pubkey []byte) error { - self.lock.RLock() - defer self.lock.RUnlock() + self.lock.Lock() + defer self.lock.Unlock() delete(self.blacklist, string(pubkey)) return nil } diff --git a/rpc/packages.go b/rpc/packages.go index ac3127356..ef31ff1e1 100644 --- a/rpc/packages.go +++ b/rpc/packages.go @@ -109,8 +109,8 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error } func (self *EthereumApi) FilterChanged(id int, reply *interface{}) error { - self.logMut.RLock() - defer self.logMut.RUnlock() + self.logMut.Lock() + defer self.logMut.Unlock() *reply = toLogs(self.logs[id]) @@ -309,8 +309,8 @@ func (p *EthereumApi) NewWhisperFilter(args *xeth.Options, reply *interface{}) e } func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error { - self.messagesMut.RLock() - defer self.messagesMut.RUnlock() + self.messagesMut.Lock() + defer self.messagesMut.Unlock() *reply = self.messages[id] From 238f39a42ecaf489f0dbbf880e6d8f8e86791f1d Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 15 Feb 2015 02:20:31 +0100 Subject: [PATCH 4/5] Validate seckey when generating pub key --- crypto/secp256k1/secp256.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crypto/secp256k1/secp256.go b/crypto/secp256k1/secp256.go index c1e37629e..4864e8d09 100644 --- a/crypto/secp256k1/secp256.go +++ b/crypto/secp256k1/secp256.go @@ -15,8 +15,9 @@ import "C" import ( "bytes" "errors" - "github.com/ethereum/go-ethereum/crypto/randentropy" "unsafe" + + "github.com/ethereum/go-ethereum/crypto/randentropy" ) //#define USE_FIELD_5X64 @@ -85,6 +86,10 @@ func GenerateKeyPair() ([]byte, []byte) { } func GeneratePubKey(seckey []byte) ([]byte, error) { + if err := VerifySeckeyValidity(seckey); err != nil { + return nil, err + } + pubkey_len := C.int(65) const seckey_len = 32 From 7299eb72e0c57d8bf7279cbf2544c266a3fd145b Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 15 Feb 2015 02:26:30 +0100 Subject: [PATCH 5/5] HTTP RPC only listen on localhost --- rpc/http/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/http/server.go b/rpc/http/server.go index 10c8fa813..dd6ba68e3 100644 --- a/rpc/http/server.go +++ b/rpc/http/server.go @@ -30,7 +30,7 @@ var rpchttplogger = logger.NewLogger("RPC-HTTP") var JSON rpc.JsonWrapper func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) { - sport := fmt.Sprintf(":%d", port) + sport := fmt.Sprintf("127.0.0.1:%d", port) l, err := net.Listen("tcp", sport) if err != nil { return nil, err