diff --git a/src/libopensc/card-sc-hsm.c b/src/libopensc/card-sc-hsm.c index 94482458..b16a0cc6 100644 --- a/src/libopensc/card-sc-hsm.c +++ b/src/libopensc/card-sc-hsm.c @@ -546,6 +546,11 @@ static int sc_hsm_compute_signature(sc_card_t *card, LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_FOUND); } + // check if datalen exceeds the buffer size + if (datalen > SC_MAX_APDU_BUFFER_SIZE) { + LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS); + } + sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x68, priv->env->key_ref[0], priv->algorithm); apdu.cla = 0x80; apdu.resp = rbuf;