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

Improve error handling in soter_rand() #485

Merged
merged 2 commits into from
Jul 4, 2019

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented Jul 3, 2019

First of all, RAND_bytes() may return -1 if the backend does not support cryptographically strong pseudo-random generators. Currently we treat this as success which is not okay. Report the error properly.

There's also a minor API mismatch between OpenSSL and BoringSSL. OpenSSL still mostly uses int for buffer lengths while BoringSSL has updated its API to use size_t. We need to check for possible overflow when using OpenSSL, and we do not need to cast anything with BoringSSL.

Finally, while we're here, improve the documentation to clarify when SOTER_FAIL may be returned and what it means. Other error codes are more or less self-explanatory so we don't mention them.

Closes #477

First of all, RAND_bytes() may return -1 if the backend does not support
cryptographically strong pseudo-random generators. Currently we treat
this as success which is not okay. Report the error properly.

There's also a minor API mismatch between OpenSSL and BoringSSL. OpenSSL
still mostly uses `int` for buffer lengths while BoringSSL has updated
its API to use `size_t`. We need to check for possible overflow when
using OpenSSL, and we do not need to cast anything with BoringSSL.

Finally, while we're here, improve the documentation to clarify when
SOTER_FAIL may be returned and what it means. Other error codes are
more or less self-explanatory so we don't mention them.
@ilammy ilammy added bug core Themis Core written in C, its packages labels Jul 3, 2019
@ilammy ilammy requested review from vixentael and Lagovas July 3, 2019 07:15
@ilammy ilammy merged commit ecec622 into cossacklabs:master Jul 4, 2019
@ilammy ilammy deleted the random-issues branch July 4, 2019 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug core Themis Core written in C, its packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

soter_rand(): cast size_t -> int -> size_t unnecessary and potentially lossy
3 participants