Skip to content

Commit

Permalink
fix remaining weakesses from audit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Z4karia committed May 23, 2024
1 parent 53c552e commit 5f4e062
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
20 changes: 0 additions & 20 deletions app/src/json/json_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ parser_error_t array_get_nth_element(const parsed_json_t *json,
uint16_t array_token_index,
uint16_t element_index,
uint16_t *token_index) {
if (array_token_index < 0 || array_token_index > json->numberOfTokens) {
return parser_no_data;
}

jsmntok_t array_token = json->tokens[array_token_index];
*token_index = array_token_index;

Expand Down Expand Up @@ -147,10 +143,6 @@ parser_error_t object_get_element_count(const parsed_json_t *json,
uint16_t object_token_index,
uint16_t *element_count) {
*element_count = 0;
if (object_token_index < 0 || object_token_index > json->numberOfTokens) {
return parser_no_data;
}

jsmntok_t object_token = json->tokens[object_token_index];
uint16_t token_index = object_token_index;
uint16_t prev_element_end = object_token.start;
Expand Down Expand Up @@ -179,10 +171,6 @@ parser_error_t object_get_nth_key(const parsed_json_t *json,
uint16_t object_element_index,
uint16_t *token_index) {
*token_index = object_token_index;
if (object_token_index < 0 || object_token_index > json->numberOfTokens) {
return parser_no_data;
}

jsmntok_t object_token = json->tokens[object_token_index];
uint16_t element_count = 0;
uint16_t prev_element_end = object_token.start;
Expand Down Expand Up @@ -214,10 +202,6 @@ parser_error_t object_get_nth_value(const parsed_json_t *json,
uint16_t object_token_index,
uint16_t object_element_index,
uint16_t *key_index) {
if (object_token_index < 0 || object_token_index > json->numberOfTokens) {
return parser_no_data;
}

CHECK_PARSER_ERR(object_get_nth_key(json, object_token_index, object_element_index, key_index))
(*key_index)++;

Expand All @@ -228,10 +212,6 @@ parser_error_t object_get_value(const parsed_json_t *json,
uint16_t object_token_index,
const char *key_name,
uint16_t *token_index) {
if (object_token_index < 0 || object_token_index > json->numberOfTokens) {
return parser_no_data;
}

const jsmntok_t object_token = json->tokens[object_token_index];

*token_index = object_token_index;
Expand Down
2 changes: 0 additions & 2 deletions app/src/tx_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
********************************************************************************/
#ifdef __cplusplus
#pragma clang diagnostic push
#pragma ide diagnostic ignored "misc-no-recursion"
#endif

#include "coin.h"
Expand Down Expand Up @@ -58,7 +57,6 @@ const char *get_required_root_item(root_item_e i) {

#ifdef __cplusplus
#pragma clang diagnostic push
#pragma ide diagnostic ignored "bugprone-branch-clone"
#endif

__Z_INLINE uint8_t get_root_max_level(root_item_e i) {
Expand Down
1 change: 0 additions & 1 deletion app/src/tx_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#ifdef __cplusplus
#pragma clang diagnostic push
#pragma ide diagnostic ignored "modernize-deprecated-headers"
#endif

#include "json/json_parser.h"
Expand Down
10 changes: 8 additions & 2 deletions app/src/tx_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int8_t is_space(char c) {

int8_t contains_whitespace(parsed_json_t *json) {
if (json == NULL){
return 1;
return 2;
}

int start = 0;
Expand Down Expand Up @@ -132,10 +132,16 @@ int8_t dictionaries_sorted(parsed_json_t *json) {
}

parser_error_t tx_validate(parsed_json_t *json) {
if (contains_whitespace(json) == 1) {
int8_t whitespace_check = contains_whitespace(json);

if (whitespace_check == 1) {
return parser_json_contains_whitespace;
}

if (whitespace_check == 2) {
return parser_json_unexpected_error;
}

if (dictionaries_sorted(json) != 1) {
return parser_json_is_not_sorted;
}
Expand Down

0 comments on commit 5f4e062

Please sign in to comment.