Skip to content

infinite while loop fix write() and clientWrite() #2

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

Merged
merged 4 commits into from
Jun 20, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/BearSSLClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ int BearSSLClient::connect(const char* host, uint16_t port)

size_t BearSSLClient::write(uint8_t b)
{

return write(&b, sizeof(b));
}

size_t BearSSLClient::write(const uint8_t *buf, size_t size)
{
br_sslio_write_all(&_ioc, buf, size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also check the return value of br_sslio_write_all ?

br_sslio_flush(&_ioc);
int ret = br_sslio_flush(&_ioc);

return size;
return ret<0?0:size;
}

int BearSSLClient::available()
Expand Down Expand Up @@ -289,5 +290,5 @@ int BearSSLClient::clientWrite(void *ctx, const unsigned char *buf, size_t len)

int w = c->write(buf, len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Client::write returns a size_t type which is unsigned, I think it's clearer if w is changed to size_t instead of int then we don't need the change below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point is that this return allow to break the while in the point of the following link, https://github.com/Rocketct/ArduinoBearSSL/blob/master/src/bearssl/ssl_io.c#L279, in case of GSMClient faillure.
If instead of a -1 it return size=0 could be possible that len in https://github.com/Rocketct/ArduinoBearSSL/blob/master/src/bearssl/ssl_io.c#L283 is never decremented.


return w;
return w>0?w:-1;
}