-
Notifications
You must be signed in to change notification settings - Fork 135
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 crash after dohandshake() fails #73
Conversation
The number of bytes received by ssl_recv() is being passed to luaL_addlstring() (in recvall()) but it was being left either uninitialized or being set to an error code. The crashing case I found was when the state was not LSEC_STATE_CONNECTED (e.g. when dohandshake() has failed) and ssl_recv() returned immediately without setting "got".
Fix crash related to incorrect buffer size
This appears to fix a pretty bad issue I've been trying to debug, but on the other hand: print(require("ssl.https").request("https://www.example.com/")) returns
|
for ( ; ; ) { | ||
ERR_clear_error(); | ||
err = SSL_read(ssl->ssl, data, (int)count); | ||
ssl->error = SSL_get_error(ssl->ssl, err); | ||
switch (ssl->error) { | ||
case SSL_ERROR_NONE: | ||
*got = err; | ||
*got = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really correct? No error → no data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong following the documentation.
It must be: *got = err;
return IO_DONE; | ||
case SSL_ERROR_ZERO_RETURN: | ||
*got = err; | ||
*got = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be removed.
We have SSL_ERROR_ZERO_RETURN only if "err == 0". Since "*got = 0;" at the beginning, the line is useless.
The number of bytes received by ssl_recv() is being passed to luaL_addlstring() (in recvall()) but it was being left either uninitialized or being set to an error code. The crashing case I found was when the state was not LSEC_STATE_CONNECTED and ssl_recv() returned immediately without setting "got".