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

Check exponent value can be expressed in uint64_t #1623

Merged
merged 1 commit into from
Nov 20, 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 @@ -112,6 +112,8 @@ and this project adheres to
- [#1621](https://github.com/iovisor/bpftrace/pull/1621)
- Only create int type Identifier when it is used in sizeof()
- [#1622](https://github.com/iovisor/bpftrace/pull/1622)
- Check exponent value can be expressed in uint64_t
- [#1623](https://github.com/iovisor/bpftrace/pull/1623)

#### Tools
- Hook up execsnoop.bt script onto `execveat` call
Expand Down
1 change: 1 addition & 0 deletions docs/fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ parallel -N1 "sed -e '/^#\!/d' -e '/\/\*.*/d' -e '/^\s\*.*/d' -e '/\/\/.*/d' -e

## Found bugs
### AFL
- [#1623](https://github.com/iovisor/bpftrace/pull/1623)
- [#1619](https://github.com/iovisor/bpftrace/pull/1619)
- [#1580](https://github.com/iovisor/bpftrace/pull/1580)
- [#1573](https://github.com/iovisor/bpftrace/pull/1573)
Expand Down
10 changes: 9 additions & 1 deletion src/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ bpftrace|perf { return Parser::make_STACK_MODE(yytext, loc); }
{call} { return Parser::make_CALL(yytext, loc); }
{call_and_builtin} { return Parser::make_CALL_BUILTIN(yytext, loc); }
{int} { return Parser::make_INT(strtoul(yytext, NULL, 0), loc); }
{exponent} { return Parser::make_INT(parse_exponent(yytext), loc); }
{exponent} {
uint64_t num;
try {
num = parse_exponent(yytext);
return Parser::make_INT(num, loc);
} catch (std::exception const &e) {
driver.error(loc, e.what());
}
}
{path} { return Parser::make_PATH(yytext, loc); }
{map} { return Parser::make_MAP(yytext, loc); }
{var} { return Parser::make_VAR(yytext, loc); }
Expand Down
4 changes: 4 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <fcntl.h>
#include <fstream>
#include <glob.h>
#include <limits>
#include <link.h>
#include <map>
#include <memory>
Expand Down Expand Up @@ -806,6 +807,9 @@ uint64_t parse_exponent(const char *str)

auto exp = strtoll(e_offset + 1, nullptr, 10);
auto num = base * std::pow(10, exp);
uint64_t max = std::numeric_limits<uint64_t>::max();
if (num > (double)max)
throw std::runtime_error(std::string(str) + " is too big for uint64_t");
return num;
}

Expand Down
1 change: 1 addition & 0 deletions tests/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ TEST(Parser, scientific_notation)
"Program\n kprobe:f\n call: print\n int: 5000000000\n");

test_parse_failure("k:f { print(5e-9); }");
test_parse_failure("k:f { print(1e100); }");
}

TEST(Parser, while_loop)
Expand Down