Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when parsing 1 byte truncated omf files #14227

Merged
merged 1 commit into from
Jun 5, 2019
Merged
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: 9 additions & 6 deletions libr/bin/p/bin_omf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,22 @@ static bool check_buffer(RBuffer *b) {
if (ch != 0x80 && ch != 0x82) {
return false;
}
ut64 length = 0;
const ut8 *buf = r_buf_data (b, &length);
ut16 rec_size = ut8p_bw (buf + 1);
ut8 str_size = *(buf + 3);
ut16 rec_size = r_buf_read_le16_at (b, 1);
ut8 str_size; (void)r_buf_read_at (b, 3, &str_size, 1);
ut64 length = r_buf_size (b);
if (str_size + 2 != rec_size || length < rec_size + 3) {
return false;
}
// check that the string is ASCII
for (i = 4; i < str_size + 4; ++i) {
if (buf[i] > 0x7f) {
for (i = 4; i < str_size + 4; i++) {
if (r_buf_read_at (b, i, &ch, 1) != 1) {
break;
}
if (ch > 0x7f) {
return false;
}
}
const ut8 *buf = r_buf_data (b, NULL);
return r_bin_checksum_omf_ok (buf, length);
}

Expand Down