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 undefined in core-test and printf-test #1345

Merged
merged 3 commits into from
Oct 8, 2019
Merged

Conversation

orivej
Copy link
Contributor

@orivej orivej commented Oct 7, 2019

  1. The change in include/fmt/core.h fixes "shift exponent -4 is negative" in
    PrintfTest.InvalidArgIndex

    do_get is called with index -1 when basic_printf_context.arg is called
    with id 4294967295 when basic_printf_context::get_arg subtracts 1 from
    arg_index 0 in the format string "%0$d".

  2. The change in test/core-test.cc fixes "reference binding to null pointer" in
    BufferTest.Ctor

    buffer.operator[] attempts to return a reference to buffer.ptr_[0] when
    ptr_ in mock_buffer<int> buffer is null.

  3. The change in test/printf-test.cc fixes "signed integer overflow" in
    PrintfTest.Length

    This occurs in TestLength<long long>("ll"), since its minimum value minus
    one does not fit in long long.

This fixes all UBSAN reports except one in format-test (#1344).

I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.

@orivej orivej force-pushed the ubsan branch 2 times, most recently from 85385fa to ad0397e Compare October 7, 2019 06:44
Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Mostly looks good with one comment inline.

@@ -1208,6 +1208,7 @@ template <typename Context> class basic_format_args {

format_arg do_get(int index) const {
format_arg arg;
if (index < 0) return arg;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed in fmt's printf implementation. It shouldn't be calling do_get with negative index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I have also split the PR into 3 commits.

Fixes "reference binding to null pointer" in BufferTest.Ctor

buffer.operator[] attempts to return a reference to `buffer.ptr_[0]` when `ptr_`
in `mock_buffer<int> buffer` is null.
Fixes "signed integer overflow" in PrintfTest.Length

This occurs in `TestLength<long long>("ll")`, since its minimum value minus one
does not fit in long long.
Printf counts arguments from 1.

Fixes "shift exponent -4 is negative" in PrintfTest.InvalidArgIndex.

`do_get` is called with index -1 when `basic_printf_context.arg` is called with
id 4294967295 when basic_printf_context::get_arg subtracts 1 from arg_index 0 in
the format string "%0$d".
@vitaut
Copy link
Contributor

vitaut commented Oct 8, 2019

Thanks!

@orivej orivej deleted the ubsan branch October 8, 2019 13:44
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.

2 participants