Skip to content

Commit

Permalink
saner hex input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancdotorg committed Jan 23, 2017
1 parent 7db5d5f commit 3bb5406
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions brainflayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ static unsigned char *mem;
static mmapf_ctx bloom_mmapf;
static unsigned char *bloom = NULL;

static unsigned char *hexed = NULL;
static size_t hexed_sz = 4096;
static unsigned char *unhexed = NULL;
static size_t unhexed_sz = 4096;

#define bail(code, ...) \
do { \
Expand Down Expand Up @@ -88,7 +88,7 @@ static inline void brainflayer_init_globals() {
if (!brainflayer_is_init) {
/* initialize buffers */
mem = chkmalloc(4096);
hexed = chkmalloc(hexed_sz);
unhexed = chkmalloc(unhexed_sz);

/* set the flag */
brainflayer_is_init = 1;
Expand Down Expand Up @@ -738,14 +738,21 @@ int main(int argc, char **argv) {
} else {
break;
}
batch_line[i][batch_line_read[i]] = 0;
if (xopt) {
if (batch_line_read[i] / 2 > unhexed_sz) {
unhexed_sz = batch_line_read[i];
unhexed = chkrealloc(unhexed, unhexed_sz);
}
// rewrite the input line from hex
unhex(batch_line[i], batch_line_read[i], batch_line[i], batch_line_sz[i]);
batch_line_read[i] /= 2;
}
batch_line[i][batch_line_read[i]] = 0;
if (input2priv(batch_priv[i], batch_line[i], batch_line_read[i]) != 0) {
fprintf(stderr, "input2priv failed! continuing...\n");
unhex(batch_line[i], batch_line_read[i], unhexed, unhexed_sz);
if (input2priv(batch_priv[i], unhexed, batch_line_read[i]/2) != 0) {
fprintf(stderr, "input2priv failed! continuing...\n");
}
} else {
if (input2priv(batch_priv[i], batch_line[i], batch_line_read[i]) != 0) {
fprintf(stderr, "input2priv failed! continuing...\n");
}
}
}

Expand All @@ -769,13 +776,6 @@ int main(int argc, char **argv) {
// reformat/populate the line if required
if (Iopt) {
hex(batch_priv[i], 32, batch_line[i], 65);
} else if (xopt) {
if (batch_line_read[i] / 2 > hexed_sz) {
hexed_sz = batch_line_read[i] * 3;
hexed = chkrealloc(hexed, hexed_sz);
}
hex(batch_line[i], batch_line_read[i], hexed, hexed_sz);
strncpy(batch_line[i], hexed, batch_line_sz[i]);
}
fprintresult(ofile, &hash160, pubhashfn[j].id, modestr, batch_line[i]);
++olines;
Expand All @@ -787,13 +787,6 @@ int main(int argc, char **argv) {
// reformat/populate the line if required
if (Iopt) {
hex(batch_priv[i], 32, batch_line[i], 65);
} else if (xopt) {
if (batch_line_read[i] / 2 > hexed_sz) {
hexed_sz = batch_line_read[i] * 3;
hexed = chkrealloc(hexed, hexed_sz);
}
hex(batch_line[i], batch_line_read[i], hexed, hexed_sz);
strncpy(batch_line[i], hexed, batch_line_sz[i]);
}
while (pubhashfn[j].fn != NULL) {
pubhashfn[j].fn(&hash160, batch_upub[i]);
Expand Down

0 comments on commit 3bb5406

Please sign in to comment.