Skip to content

Commit

Permalink
swap alloca for malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
mildsunrise committed Mar 16, 2023
1 parent 76e2679 commit 8c81167
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion virtualsmartcard/src/vpcd/vpcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 8c81167

Please sign in to comment.