mirror of
https://github.com/btcsuite/btcd.git
synced 2025-02-22 14:22:49 +01:00
Merge pull request #2233 from jharveyb/txid_string_check
wire: check TXID length before creating outpoint
This commit is contained in:
commit
029e5a3cb5
2 changed files with 14 additions and 0 deletions
|
@ -229,6 +229,11 @@ func NewOutPointFromString(outpoint string) (*OutPoint, error) {
|
|||
if len(parts) != 2 {
|
||||
return nil, errors.New("outpoint should be of the form txid:index")
|
||||
}
|
||||
|
||||
if len(parts[0]) != chainhash.MaxHashStringSize {
|
||||
return nil, errors.New("outpoint txid should be 64 hex chars")
|
||||
}
|
||||
|
||||
hash, err := chainhash.NewHashFromStr(parts[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -849,6 +849,15 @@ func TestTxOutPointFromString(t *testing.T) {
|
|||
},
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
name: "normal outpoint 2 with 31-byte txid",
|
||||
input: "c7762a68ff164352bd31fd95fa875204e811c09acef40ba781787eb28e3b55:42",
|
||||
result: &OutPoint{
|
||||
Hash: hashFromStr("c7762a68ff164352bd31fd95fa875204e811c09acef40ba781787eb28e3b55"),
|
||||
Index: 42,
|
||||
},
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
name: "bad string",
|
||||
input: "not_outpoint_not_outpoint_not_outpoint",
|
||||
|
|
Loading…
Add table
Reference in a new issue