From 8c8116724e852b9c58a8157d49cf8c1dec652422 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Thu, 16 Mar 2023 10:58:12 +0100 Subject: [PATCH] swap alloca for malloc --- virtualsmartcard/src/vpcd/vpcd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/virtualsmartcard/src/vpcd/vpcd.c b/virtualsmartcard/src/vpcd/vpcd.c index a2047fe..882feb1 100644 --- a/virtualsmartcard/src/vpcd/vpcd.c +++ b/virtualsmartcard/src/vpcd/vpcd.c @@ -226,8 +226,14 @@ static ssize_t sendToVICC(struct vicc_ctx *ctx, size_t length, const unsigned ch return -1; } + /* allocate buffer for outgoing message */ + sendBuffer = (char *) malloc(length + 2); + if (sendBuffer == NULL) { + errno = ENOMEM; + return -1; + } + /* send size of message on 2 bytes */ - sendBuffer = (char *) alloca(length + 2); size = htons((uint16_t) length); memcpy(sendBuffer, &size, 2); memcpy(sendBuffer + 2, buffer, length); @@ -236,6 +242,7 @@ static ssize_t sendToVICC(struct vicc_ctx *ctx, size_t length, const unsigned ch if (r < 0) vicc_eject(ctx); + free(sendBuffer); return r; }