diff options
author | Kurt Roeckx <kurt@roeckx.be> | 2016-11-15 18:58:52 +0100 |
---|---|---|
committer | Kurt Roeckx <kurt@roeckx.be> | 2016-11-21 21:59:35 +0100 |
commit | 11f1fd4b0d1b3aef5c79b843d081dbb9bcd0b85f (patch) | |
tree | 1254a328bf2ce5d6123c22099f86ffb6eb64fec7 /test | |
parent | c947fa492ea8d727929d02605a41979cfff7b261 (diff) |
Make SSL_read and SSL_write return the old behaviour and document it.
Backport of beacb0f0c1ae7b0542fe053b95307f515b578eb7, revert of
122580ef71e4e5f355a1a104c9bfb36feee43759
Fixes: #1903
Reviewed-by: Matt Caswell <matt@openssl.org>
GH: #1966
Diffstat (limited to 'test')
-rw-r--r-- | test/asynciotest.c | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/test/asynciotest.c b/test/asynciotest.c index 0d382d70f6..133e3d5a97 100644 --- a/test/asynciotest.c +++ b/test/asynciotest.c @@ -297,32 +297,59 @@ int main(int argc, char *argv[]) * we hit at least one async event in both reading and writing */ for (j = 0; j < 2; j++) { + int len; + /* * Write some test data. It should never take more than 2 attempts - * (the first one might be a retryable fail). A zero return from - * SSL_write() is a non-retryable failure, so fail immediately if - * we get that. + * (the first one might be a retryable fail). */ - for (ret = -1, i = 0; ret < 0 && i < 2 * sizeof(testdata); i++) - ret = SSL_write(clientssl, testdata, sizeof(testdata)); - if (ret <= 0) { - printf("Test %d failed: Failed to write app data\n", test); + for (ret = -1, i = 0, len = 0; len != sizeof(testdata) && i < 2; + i++) { + ret = SSL_write(clientssl, testdata + len, + sizeof(testdata) - len); + if (ret > 0) { + len += ret; + } else { + int ssl_error = SSL_get_error(clientssl, ret); + + if (ssl_error == SSL_ERROR_SYSCALL || + ssl_error == SSL_ERROR_SSL) { + printf("Test %d failed: Failed to write app data\n", test); + err = -1; + goto end; + } + } + } + if (len != sizeof(testdata)) { + err = -1; + printf("Test %d failed: Failed to write all app data\n", test); goto end; } /* * Now read the test data. It may take more attemps here because * it could fail once for each byte read, including all overhead - * bytes from the record header/padding etc. Fail immediately if we - * get a zero return from SSL_read(). + * bytes from the record header/padding etc. */ - for (ret = -1, i = 0; ret < 0 && i < MAX_ATTEMPTS; i++) - ret = SSL_read(serverssl, buf, sizeof(buf)); - if (ret <= 0) { - printf("Test %d failed: Failed to read app data\n", test); - goto end; + for (ret = -1, i = 0, len = 0; len != sizeof(testdata) && + i < MAX_ATTEMPTS; i++) + { + ret = SSL_read(serverssl, buf + len, sizeof(buf) - len); + if (ret > 0) { + len += ret; + } else { + int ssl_error = SSL_get_error(serverssl, ret); + + if (ssl_error == SSL_ERROR_SYSCALL || + ssl_error == SSL_ERROR_SSL) { + printf("Test %d failed: Failed to read app data\n", test); + err = -1; + goto end; + } + } } - if (ret != sizeof(testdata) + if (len != sizeof(testdata) || memcmp(buf, testdata, sizeof(testdata)) != 0) { + err = -1; printf("Test %d failed: Unexpected app data received\n", test); goto end; } |