Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/cli/such.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,9 @@ int main(int argc, char* argv[])
char* mnemonic_in = 0;
char* pass = 0;
char* entropy = 0;
/* entropy_size points at a literal, so -e needs somewhere writable.
+ 1 for the terminator ENTROPY_SIZE_STRING_SIZE does not include. */
char entropy_size_buf[ENTROPY_SIZE_STRING_SIZE + 1];
char* entropy_size = "256";
MNEMONIC mnemonic = {0};
SEED seed = {0};
Expand Down Expand Up @@ -1252,7 +1255,17 @@ int main(int argc, char* argv[])
return showError("Parameter -e cannot be used with -y");
entropy = optarg;
if (entropy != NULL){
sprintf(entropy_size, "%zu", strlen(entropy) / HEX_CHARS_PER_BYTE * 8);
/* Bound first: unbounded optarg gives four or more
digits and snprintf truncates rather than overflows. */
size_t entropy_hex_len = strlen(entropy);
if (entropy_hex_len > MAX_ENTROPY_STRING_SIZE - 1)
return showError("Parameter -e exceeds the maximum entropy size");

/* sprintf through the "256" literal wrote to read-only
memory and crashed on every use of -e. */
snprintf(entropy_size_buf, sizeof(entropy_size_buf), "%zu",
entropy_hex_len / HEX_CHARS_PER_BYTE * 8);
entropy_size = entropy_size_buf;
}

break;
Expand Down
Loading