Skip to content

Commit

Permalink
Merge pull request #54 from provenance-io/enforce-signature-list-size
Browse files Browse the repository at this point in the history
enforce the signature list size to prevent index out of bounds
  • Loading branch information
mtps authored Oct 3, 2023
2 parents 3a6d476 + 59c4f71 commit d784c46
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ open class AbstractPbClient<T : ManagedChannelBuilder<T>>(
gasEstimate: GasEstimate,
mode: ServiceOuterClass.BroadcastMode = ServiceOuterClass.BroadcastMode.BROADCAST_MODE_SYNC,
txHashHandler: PreBroadcastTxHashHandler? = null,
signatures: List<ByteArray?> = emptyList(),
signatures: List<ByteArray?> = List(baseReq.signers.size) { null },
): ServiceOuterClass.BroadcastTxResponse {
val authInfoBytes = baseReq.buildAuthInfo(gasEstimate).toByteString()
val txBodyBytes = baseReq.body.toByteString()

require(signatures.size == baseReq.signers.size) {
"The number of signatures must match the number of signers. A null/empty signature entry will sign using the Signer implementation."
}

val txRaw = baseReq.signers.mapIndexed { index, baseReqSigner ->
signatures[index]?.takeIf { it.isNotEmpty() }
?: baseReqSigner.signer.sign(
Expand Down Expand Up @@ -169,7 +173,7 @@ open class AbstractPbClient<T : ManagedChannelBuilder<T>>(
feeGranter: String? = null,
feePayer: String? = null,
txHashHandler: PreBroadcastTxHashHandler? = null,
signatures: List<ByteArray?> = emptyList(),
signatures: List<ByteArray?> = List(signers.size) { null },
): ServiceOuterClass.BroadcastTxResponse =
baseRequest(
txBody = txBody,
Expand Down

0 comments on commit d784c46

Please sign in to comment.