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

Conversation

mmisono
Copy link
Collaborator

@mmisono mmisono commented Nov 15, 2020

Undefined Sanitizer found the following error.

sudo ./src/bpftrace -e 'BEGIN {@ = 1e30;}'
/home/ubuntu/work/bpftrace/src/utils.cpp:809:10: runtime error: 1e+30 is outside the range of representable values of type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/ubuntu/work/bpftrace/src/utils.cpp:809:10 in
Attaching 1 probe...
^C

@: 0

To fix this, in the parse_exponent(), check the exponent value and if
it's bigger than uint64_t'x max value, throw exception. The Lexer then
make an error.

Now it becomes

% sudo ./src/bpftrace -e 'BEGIN {@ = 1e30;}'
stdin:1:12-16: ERROR: 1e30 is too big for uint64_t
BEGIN {@ = 1e30;}
           ~~~~
stdin:1:12-17: ERROR: syntax error, unexpected ;
BEGIN {@ = 1e30;}
           ~~~~~
Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

@mmisono
Copy link
Collaborator Author

mmisono commented Nov 15, 2020

The changelong and docs/fuzzing.md need to be updated for #1622, #1621, and this. I'll do it after reviews and #1617 is merged.

@mmisono mmisono added the do-not-merge Changes are not ready to be merged into master yet label Nov 15, 2020
Undefined Sanitizer found the following error.

```
sudo ./src/bpftrace -e 'BEGIN {@ = 1e30;}'
/home/ubuntu/work/bpftrace/src/utils.cpp:809:10: runtime error: 1e+30 is outside the range of representable values of type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/ubuntu/work/bpftrace/src/utils.cpp:809:10 in
Attaching 1 probe...
^C

@: 0
```

To fix this, in the parse_exponent(), check the exponent value and if
it's bigger than uint64_t'x max value, throw exception. The Lexer then
make an error.

Now it becomes

```
% sudo ./src/bpftrace -e 'BEGIN {@ = 1e30;}'
stdin:1:12-16: ERROR: 1e30 is too big for uint64_t
BEGIN {@ = 1e30;}
           ~~~~
stdin:1:12-17: ERROR: syntax error, unexpected ;
BEGIN {@ = 1e30;}
           ~~~~~
```
@mmisono mmisono removed the do-not-merge Changes are not ready to be merged into master yet label Nov 20, 2020
@mmisono mmisono merged commit 338e983 into bpftrace:master Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants