Skip to content

Commit 50b9cb7

Browse files
committed
[Refactor] check scriptsig size in CheckBlockSignature
1 parent e916c0a commit 50b9cb7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/blocksignature.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,17 @@ bool CheckBlockSignature(const CBlock& block)
7676
// p2pk scriptsig only contains the signature and p2pkh scriptpubkey only contain the hash.
7777
return false;
7878
} else {
79-
int start = 1 + (int) *txin.scriptSig.begin(); // skip sig
79+
unsigned int start = 1 + (unsigned int) *txin.scriptSig.begin(); // skip sig
80+
if (start >= txin.scriptSig.size() - 1) return false;
8081
pubkey = CPubKey(txin.scriptSig.begin()+start+1, txin.scriptSig.end());
8182
}
8283
} else if (whichType == TX_COLDSTAKE) {
8384
// pick the public key from the P2CS input
8485
const CTxIn& txin = block.vtx[1]->vin[0];
85-
int start = 1 + (int) *txin.scriptSig.begin(); // skip sig
86+
unsigned int start = 1 + (unsigned int) *txin.scriptSig.begin(); // skip sig
87+
if (start >= txin.scriptSig.size() - 1) return false;
8688
start += 1 + (int) *(txin.scriptSig.begin()+start); // skip flag
89+
if (start >= txin.scriptSig.size() - 1) return false;
8790
pubkey = CPubKey(txin.scriptSig.begin()+start+1, txin.scriptSig.end());
8891
}
8992
}

0 commit comments

Comments
 (0)