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

Running with UBSan throws runtime error regarding bitshift #52

Open
DanielG opened this issue Dec 18, 2019 · 0 comments · May be fixed by #53
Open

Running with UBSan throws runtime error regarding bitshift #52

DanielG opened this issue Dec 18, 2019 · 0 comments · May be fixed by #53

Comments

@DanielG
Copy link

DanielG commented Dec 18, 2019

When running theft with ubsan enabled (-fsanitize=undefined) I get the following error:

.src/theft_random.c:79:21: runtime error: shift exponent 64 is too large for 64-bit type 'long unsigned int'

At the mentioned source location we have:

    uint8_t shift = 0;
[...]
        uint8_t take = 64 - shift;
[...]
        t->prng.buf >>= take;

According to the C standard shifting by more than the types size is undefined behaviour:

The behavior is undefined in the following circumstances:
[...]

  • An expression is shifted by a negative number or by an amount greater than or equal
    to the width of the promoted expression (6.5.7).
DanielG added a commit to DanielG/theft that referenced this issue Dec 18, 2019
Shifting a type by >=sizeof(type)*8 is undefined behaviour in C. Since
t->prng.buf is overwritten on the next iteration anyways this thankfully
isn't a real bug here.

Fixes silentbicycle#52
DanielG added a commit to DanielG/theft that referenced this issue Dec 18, 2019
Shifting a type by >=sizeof(type)*8 is undefined behaviour in C. Since
t->prng.buf is overwritten on the next iteration anyways this thankfully
isn't a real bug here.

Fixes silentbicycle#52
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 a pull request may close this issue.

1 participant