Skip to content

Commit

Permalink
revert success on EOF and align with OpenSSL
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel40791765 committed May 8, 2024
1 parent 7c7f0f8 commit 3edd87c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crypto/bio/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int BIO_read_ex(BIO *bio, void *data, size_t data_len, size_t *read_bytes) {
}

int ret = BIO_read(bio, data, read_len);
if (ret >= 0) {
if (ret > 0) {
*read_bytes = ret;
return 1;
} else {
Expand Down
4 changes: 2 additions & 2 deletions crypto/bio/bio_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,11 @@ TEST(BIOTest, ReadWriteEx) {

// Test that |BIO_write/read_ex| align with their non-ex counterparts, when
// encountering NULL data. EOF in |BIO_read| is indicated by returning 0.
// In AWS-LC's |BIO_read_ex|, this should return success and set |read| to 0.
// In |BIO_read_ex| however, EOF returns a failure and sets |read| to 0.
EXPECT_FALSE(BIO_write(bio.get(), nullptr, 0));
EXPECT_FALSE(BIO_write_ex(bio.get(), nullptr, 0, &written));
EXPECT_EQ(written, (size_t)0);
EXPECT_EQ(BIO_read(bio.get(), nullptr, 0), 0);
ASSERT_TRUE(BIO_read_ex(bio.get(), nullptr, 0, &read));
EXPECT_FALSE(BIO_read_ex(bio.get(), nullptr, 0, &read));
EXPECT_EQ(read, (size_t)0);
}
8 changes: 3 additions & 5 deletions include/openssl/bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ OPENSSL_EXPORT int BIO_read(BIO *bio, void *data, int len);
// BIO_read_ex calls |BIO_read| and stores the number of bytes read in
// |read_bytes|. It returns one on success and zero otherwise.
//
// Note: OpenSSL's |BIO_read_ex| returns zero on EOF. This disallows any
// mechanism to notify the user that an EOF has occurred and renders this API
// unusable. See openssl/openssl#8208.
// |BIO_read_ex| will return one for success and set |read_bytes| to 0 on EOF in
// AWS-LC.
// WARNING: Don't use this, use |BIO_read| instead. |BIO_read_ex| returns zero
// on EOF, which disallows any mechanism to notify the user that an EOF has
// occurred and renders this API unusable. See openssl/openssl#8208.
OPENSSL_EXPORT int BIO_read_ex(BIO *bio, void *data, size_t data_len,
size_t *read_bytes);

Expand Down

0 comments on commit 3edd87c

Please sign in to comment.