Skip to content

Commit

Permalink
fix heap overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Aug 22, 2024
1 parent 991d66a commit 204c23d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/src/items_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
extern char base64_hash[45];

items_error_t items_stdToDisplayString(item_t item, char *outVal, uint16_t outValLen) {
parsed_json_t *json_all = &(parser_getParserTxObj()->json);
jsmntok_t *token = &(json_all->tokens[item.json_token_index]);
uint16_t len = token->end - token->start + 1;
const parsed_json_t *json_all = &(parser_getParserTxObj()->json);
const jsmntok_t *token = &(json_all->tokens[item.json_token_index]);
const uint16_t len = token->end - token->start;

if (len == 1) return items_length_zero;
if (len == 0) return items_length_zero;

if (len > outValLen) {
if (len >= outValLen) {
return items_data_too_large;
}

snprintf(outVal, len, "%s", json_all->buffer + token->start);
snprintf(outVal, outValLen, "%.*s", len, json_all->buffer + token->start);

return items_ok;
}
Expand Down

1 comment on commit 204c23d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format reports: 1 file(s) not formatted
  • app/src/items_format.c

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.