Skip to content

Commit

Permalink
snprintf use stack memory
Browse files Browse the repository at this point in the history
  • Loading branch information
estkme committed Nov 23, 2023
1 parent 760da11 commit 67b0ab8
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions interface/apdu/pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,30 +379,21 @@ static int pcsc_list_iter(int index, const char *reader, void *userdata)
{
cJSON *json = userdata;
cJSON *jreader;
char index_str[16];

char *index_str;
snprintf(index_str, sizeof(index_str), "%d", index);

jreader = cJSON_CreateObject();
if (!jreader)
{
return -1;
}

index_str = malloc(16);
if (!index_str)
{
return -1;
}

snprintf(index_str, 16, "%d", index);

if (!cJSON_AddStringToObject(jreader, "env", index_str))
{
return -1;
}

free(index_str);

if (!cJSON_AddStringToObject(jreader, "name", reader))
{
return -1;
Expand Down

0 comments on commit 67b0ab8

Please sign in to comment.