Skip to content

Commit 59afb33

Browse files
committed
Make SSL_read_ex and SSL_write_ex wrappers set number of bytes on failure.
This matches the behavior of the real OpenSSL functions do. Found by the ZeroPath AI Security Engineer <https://zeropath.com>
1 parent ab66fe5 commit 59afb33

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/ssl_compat/ssl_compat.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,27 @@
3131

3232
/*
3333
* Emulate SSL_read_ex() using SSL_read().
34-
* Unlike the real SSL_read_ex(), this can return -1 on error.
3534
*/
3635
int
3736
SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes)
3837
{
3938
int nr = SSL_read(ssl, buf, (int)num);
40-
if (nr <= 0)
41-
return nr;
39+
if (nr < 0)
40+
nr = 0;
4241
*readbytes = (size_t)nr;
43-
return 1;
42+
return nr > 0;
4443
}
4544

4645
/*
4746
* Emulate SSL_write_ex() using SSL_write().
48-
* Unlike the real SSL_write_ex(), this can return -1 on error.
4947
*/
5048
int
5149
SSL_write_ex(SSL *ssl, const void *buf, size_t num, size_t *written)
5250
{
5351
int nw = SSL_write(ssl, buf, (int)num);
54-
if (nw <= 0)
55-
return nw;
52+
if (nw < 0)
53+
nw = 0;
5654
*written = (size_t)nw;
57-
return 1;
55+
return nw > 0;
5856
}
5957
#endif /* HAVE_OPENSSL && !HAVE_SSL_READ_EX */

0 commit comments

Comments
 (0)