Skip to content

Commit

Permalink
Merge pull request #2 from blooo-io/rollback-secure-len-RSPEC-5813
Browse files Browse the repository at this point in the history
fix(sonar): rollback sonar RSPEC-5813
  • Loading branch information
n4l5u0r authored Oct 29, 2021
2 parents f12c855 + 065d74e commit 6e5cfaa
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#include "paraswap_plugin.h"

int secure_len(char *src) {
char dest[256];
strncpy(dest, src, sizeof dest); // Truncation may happen
dest[sizeof dest - 1] = 0;
return strlen(dest); // Compliant: "dest" is guaranteed to be null-terminated
}

// Prepend `dest` with `ticker`.
// Dest must be big enough to hold `ticker` + `dest` + `\0`.
static void prepend_ticker(char *dest, size_t destsize, const char *ticker) {
if (dest == NULL || ticker == NULL) {
THROW(0x6503);
}
uint8_t ticker_len = secure_len(ticker);
uint8_t dest_len = secure_len(dest);
uint8_t ticker_len = strlen(ticker);
uint8_t dest_len = strlen(dest);

if (dest_len + ticker_len >= destsize) {
THROW(0x6503);
Expand Down
Binary file modified tests/elfs/paraswap_nanos.elf
Binary file not shown.
Binary file modified tests/elfs/paraswap_nanox.elf
Binary file not shown.

0 comments on commit 6e5cfaa

Please sign in to comment.