Skip to content

Commit 0f199fc

Browse files
update read/written bytes only on success
1 parent 86ec698 commit 0f199fc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

crypto/bio/bio.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,11 @@ 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-
*read_bytes = ret;
202201
if (ret > 0) {
202+
*read_bytes = ret;
203203
return 1;
204204
} else {
205+
*read_bytes = 0;
205206
return 0;
206207
}
207208
}
@@ -268,12 +269,15 @@ int BIO_write_ex(BIO *bio, const void *data, size_t data_len, size_t *written_by
268269
}
269270

270271
int ret = BIO_write(bio, data, write_len);
271-
if (written_bytes != NULL) {
272-
*written_bytes = ret;
273-
}
274272
if (ret > 0) {
273+
if (written_bytes != NULL) {
274+
*written_bytes = ret;
275+
}
275276
return 1;
276277
} else {
278+
if (written_bytes != NULL) {
279+
*written_bytes = 0;
280+
}
277281
return 0;
278282
}
279283
}

crypto/bio/bio_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,12 @@ TEST(BIOTest, ReadWriteEx) {
10911091

10921092
// Test that |BIO_write/read_ex| align with their non-ex counterparts, when
10931093
// encountering NULL data.
1094+
written = 1;
10941095
EXPECT_FALSE(BIO_write(bio.get(), nullptr, 0));
10951096
EXPECT_FALSE(BIO_write_ex(bio.get(), nullptr, 0, &written));
1097+
EXPECT_EQ(written, (size_t)0);
1098+
read = 1;
10961099
EXPECT_FALSE(BIO_read(bio.get(), nullptr, 0));
10971100
EXPECT_FALSE(BIO_read_ex(bio.get(), nullptr, 0, &read));
1101+
EXPECT_EQ(read, (size_t)0);
10981102
}

0 commit comments

Comments
 (0)