Skip to content

Commit

Permalink
Merge pull request #28 from trilitech/elric1@prep-for-scan-build
Browse files Browse the repository at this point in the history
In prep for scan-build, we eliminate use of strcpy(3)
  • Loading branch information
elric1 authored Sep 27, 2023
2 parents 7f836db + 8ed4e83 commit c5230d6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ handle_data_apdu_blind(packet_t *pkt)
global.apdu.sign.step = SIGN_ST_WAIT_USER_INPUT;

transaction_type = type;
strcpy(hash, obuf);
STRLCPY(hash, obuf);

nbgl_useCaseReviewStart(&C_tezos, request, NULL, "Reject request",
continue_blindsign_cb, reject_blindsign_cb);
Expand Down
2 changes: 2 additions & 0 deletions app/src/parser/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@
#undef MIN
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

#define STRLCPY(x, y) strlcpy((x), (y), sizeof(x))
32 changes: 16 additions & 16 deletions app/src/parser/operation_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ tz_operation_parser_init(tz_parser_state *state, uint16_t size,
if (!skip_magic) {
op->stack[0].step = TZ_OPERATION_STEP_MAGIC;
} else {
strcpy(state->field_name, "Branch");
STRLCPY(state->field_name, "Branch");
op->stack[0].step = TZ_OPERATION_STEP_BRANCH;
push_frame(state, TZ_OPERATION_STEP_READ_BYTES); // ignore result,
// assume success
Expand Down Expand Up @@ -362,7 +362,7 @@ tz_operation_parser_step(tz_parser_state *state)
tz_must(tz_parser_read(state, &b));
switch (b) {
case 3: // manager/anonymous operation
strcpy(state->field_name, "Branch");
STRLCPY(state->field_name, "Branch");
op->stack[0].step = TZ_OPERATION_STEP_BRANCH;
push_frame(state,
TZ_OPERATION_STEP_READ_BYTES); // ignore result,
Expand Down Expand Up @@ -423,7 +423,7 @@ tz_operation_parser_step(tz_parser_state *state)
case TZ_OPERATION_STEP_READ_MICHELINE: {
if (!op->frame->step_read_micheline.inited) {
op->frame->step_read_micheline.inited = 1;
strcpy(state->field_name, op->frame->step_read_micheline.name);
STRLCPY(state->field_name, op->frame->step_read_micheline.name);
tz_micheline_parser_init(state);
}
tz_micheline_parser_step(state);
Expand Down Expand Up @@ -652,27 +652,27 @@ tz_operation_parser_step(tz_parser_state *state)
tz_must(tz_parser_read(state, &b));
switch (b) {
case 0:
strcpy((char *)CAPTURE, "default");
strlcpy((char *)CAPTURE, "default", sizeof(CAPTURE));
tz_must(tz_print_string(state));
break;
case 1:
strcpy((char *)CAPTURE, "root");
strlcpy((char *)CAPTURE, "root", sizeof(CAPTURE));
tz_must(tz_print_string(state));
break;
case 2:
strcpy((char *)CAPTURE, "do");
strlcpy((char *)CAPTURE, "do", sizeof(CAPTURE));
tz_must(tz_print_string(state));
break;
case 3:
strcpy((char *)CAPTURE, "set_delegate");
strlcpy((char *)CAPTURE, "set_delegate", sizeof(CAPTURE));
tz_must(tz_print_string(state));
break;
case 4:
strcpy((char *)CAPTURE, "remove_delegate");
strlcpy((char *)CAPTURE, "remove_delegate", sizeof(CAPTURE));
tz_must(tz_print_string(state));
break;
case 5:
strcpy((char *)CAPTURE, "deposit");
strlcpy((char *)CAPTURE, "deposit", sizeof(CAPTURE));
tz_must(tz_print_string(state));
break;
case 0xFF:
Expand Down Expand Up @@ -705,7 +705,7 @@ tz_operation_parser_step(tz_parser_state *state)
if (!field->required)
tz_must(tz_parser_read(state, &present));
if (!field->skip)
strcpy(state->field_name, name);
STRLCPY(state->field_name, name);
op->frame->step_operation.field++;
if (!present) {
if (field->display_none) {
Expand Down Expand Up @@ -817,7 +817,7 @@ tz_operation_parser_step(tz_parser_state *state)
op->frame->step_size.size_len = 4;
tz_must(push_frame(state,
TZ_OPERATION_STEP_READ_SMART_ENTRYPOINT));
strcpy(state->field_name, "Entrypoint");
STRLCPY(state->field_name, "Entrypoint");
op->frame->step_read_string.ofs = 0;
op->frame->step_read_string.skip = field->skip;
break;
Expand Down Expand Up @@ -921,10 +921,10 @@ tz_operation_parser_step(tz_parser_state *state)
tz_must(tz_parser_read(state, &b));
switch (b) {
case 0:
strcpy((char *)CAPTURE, "arith");
strlcpy((char *)CAPTURE, "arith", sizeof(CAPTURE));
break;
case 1:
strcpy((char *)CAPTURE, "wasm_2_0_0");
strlcpy((char *)CAPTURE, "wasm_2_0_0", sizeof(CAPTURE));
break;
default:
tz_raise(INVALID_TAG);
Expand All @@ -937,13 +937,13 @@ tz_operation_parser_step(tz_parser_state *state)
tz_must(tz_parser_read(state, &b));
switch (b) {
case 0:
strcpy((char *)CAPTURE, "yay");
strlcpy((char *)CAPTURE, "yay", sizeof(CAPTURE));
break;
case 1:
strcpy((char *)CAPTURE, "nay");
strlcpy((char *)CAPTURE, "nay", sizeof(CAPTURE));
break;
case 2:
strcpy((char *)CAPTURE, "pass");
strlcpy((char *)CAPTURE, "pass", sizeof(CAPTURE));
break;
default:
tz_raise(INVALID_TAG);
Expand Down
2 changes: 0 additions & 2 deletions app/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "globals.h"

#define STRLCPY(x, y) strlcpy((x), (y), sizeof(x))

/*
* Debugging macros.
*
Expand Down

0 comments on commit c5230d6

Please sign in to comment.