Skip to content

Commit 3edd87c

Browse files
revert success on EOF and align with OpenSSL
1 parent 7c7f0f8 commit 3edd87c

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

crypto/bio/bio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int BIO_read_ex(BIO *bio, void *data, size_t data_len, size_t *read_bytes) {
198198
}
199199

200200
int ret = BIO_read(bio, data, read_len);
201-
if (ret >= 0) {
201+
if (ret > 0) {
202202
*read_bytes = ret;
203203
return 1;
204204
} else {

crypto/bio/bio_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,11 +1096,11 @@ TEST(BIOTest, ReadWriteEx) {
10961096

10971097
// Test that |BIO_write/read_ex| align with their non-ex counterparts, when
10981098
// encountering NULL data. EOF in |BIO_read| is indicated by returning 0.
1099-
// In AWS-LC's |BIO_read_ex|, this should return success and set |read| to 0.
1099+
// In |BIO_read_ex| however, EOF returns a failure and sets |read| to 0.
11001100
EXPECT_FALSE(BIO_write(bio.get(), nullptr, 0));
11011101
EXPECT_FALSE(BIO_write_ex(bio.get(), nullptr, 0, &written));
11021102
EXPECT_EQ(written, (size_t)0);
11031103
EXPECT_EQ(BIO_read(bio.get(), nullptr, 0), 0);
1104-
ASSERT_TRUE(BIO_read_ex(bio.get(), nullptr, 0, &read));
1104+
EXPECT_FALSE(BIO_read_ex(bio.get(), nullptr, 0, &read));
11051105
EXPECT_EQ(read, (size_t)0);
11061106
}

include/openssl/bio.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ OPENSSL_EXPORT int BIO_read(BIO *bio, void *data, int len);
113113
// BIO_read_ex calls |BIO_read| and stores the number of bytes read in
114114
// |read_bytes|. It returns one on success and zero otherwise.
115115
//
116-
// Note: OpenSSL's |BIO_read_ex| returns zero on EOF. This disallows any
117-
// mechanism to notify the user that an EOF has occurred and renders this API
118-
// unusable. See openssl/openssl#8208.
119-
// |BIO_read_ex| will return one for success and set |read_bytes| to 0 on EOF in
120-
// AWS-LC.
116+
// WARNING: Don't use this, use |BIO_read| instead. |BIO_read_ex| returns zero
117+
// on EOF, which disallows any mechanism to notify the user that an EOF has
118+
// occurred and renders this API unusable. See openssl/openssl#8208.
121119
OPENSSL_EXPORT int BIO_read_ex(BIO *bio, void *data, size_t data_len,
122120
size_t *read_bytes);
123121

0 commit comments

Comments
 (0)