Skip to content

Commit

Permalink
Fix rfraw builder overflow (closes merbanan#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Nov 2, 2020
1 parent 1d1cd5a commit c72b561
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pulse_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ static void histogram_print(histogram_t const *hist, uint32_t samp_rate)
}

#define HEXSTR_BUILDER_SIZE 1024
#define HEXSTR_MAX_COUNT 32

/// Hex string builder
typedef struct hexstr {
Expand Down Expand Up @@ -365,10 +366,10 @@ void pulse_analyzer(pulse_data_t *data, int package_type)
// pick last gap length but a most the 4th
int limit_bin = MIN(3, hist_gaps.bins_count - 1);
int limit = hist_gaps.bins[limit_bin].min;
hexstr_t hexstrs[32] = {{{0}}};
hexstr_t hexstrs[HEXSTR_MAX_COUNT] = {{{0}}};
unsigned hexstr_cnt = 0;
unsigned i = 0;
while (i < data->num_pulses) {
while (i < data->num_pulses && hexstr_cnt < HEXSTR_MAX_COUNT) {
hexstr_t *hexstr = &hexstrs[hexstr_cnt];
hexstr_push_byte(hexstr, 0xaa);
hexstr_push_byte(hexstr, 0xb0);
Expand Down Expand Up @@ -409,6 +410,9 @@ void pulse_analyzer(pulse_data_t *data, int package_type)
hexstr_print(&hexstrs[i], stderr);
}
fprintf(stderr, "\n");
if (hexstr_cnt >= HEXSTR_MAX_COUNT) {
fprintf(stderr, "Too many pulse groups (%u pulses missed in rfraw)\n", data->num_pulses - i);
}
}
}

Expand Down

0 comments on commit c72b561

Please sign in to comment.