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 a possible integer overflow #1580

Merged
merged 1 commit into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ and this project adheres to
- [#1572](https://github.com/iovisor/bpftrace/pull/1572)
- Check string comparison size
- [#1573](https://github.com/iovisor/bpftrace/pull/1573)
- Fix a possible integer overflow
- [#1580](https://github.com/iovisor/bpftrace/pull/1580)

#### Tools
- Hook up execsnoop.bt script onto `execveat` call
Expand Down
13 changes: 12 additions & 1 deletion src/clang_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,19 @@ static bool getBitfield(CXCursor c, Bitfield &bitfield)

size_t bitfield_offset = clang_Cursor_getOffsetOfField(c) % 8;
size_t bitfield_bitwidth = clang_getFieldDeclBitWidth(c);
size_t bitfield_bitdidth_max = sizeof(uint64_t) * 8;

bitfield.mask = (1 << bitfield_bitwidth) - 1;
if (bitfield_bitwidth > bitfield_bitdidth_max)
{
LOG(WARNING) << "bitfiled bitwidth " << bitfield_bitwidth
<< "is not supporeted."
<< " Use bitwidth " << bitfield_bitdidth_max;
bitfield_bitwidth = bitfield_bitdidth_max;
}
if (bitfield_bitwidth == bitfield_bitdidth_max)
bitfield.mask = std::numeric_limits<uint64_t>::max();
else
bitfield.mask = (1ULL << bitfield_bitwidth) - 1;
bitfield.access_rshift = bitfield_offset;
// Round up to nearest byte
bitfield.read_bytes = (bitfield_offset + bitfield_bitwidth + 7) / 8;
Expand Down
2 changes: 1 addition & 1 deletion src/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct Bitfield
// Then rshift the resulting value by `access_rshift` to get field value
size_t access_rshift;
// Then logical AND `mask` to mask out everything but this bitfield
size_t mask;
uint64_t mask;
};

struct Field
Expand Down