Skip to content

Commit e6773a9

Browse files
committed
osdc/Striper: relax assert in assemble_result() for raw buffers
The previous commit uncovered an old bug, introduced in commit 9867804 ("Striper: Add function 'assemble_result(CephContext *cct, char *buffer, size_t len)' in StripedReadResult."). The buffer is allowed to be NULL when assemble_result() is called -- it becomes a problem only if some data was read. Strengthen ZeroLengthRead and ZeroLengthWrite tests to cover both a bogus pointer and a NULL pointer for buffer. Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 1484480 commit e6773a9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/osdc/Striper.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,14 @@ void Striper::StripedReadResult::assemble_result(CephContext *cct,
485485

486486
void Striper::StripedReadResult::assemble_result(CephContext *cct, char *buffer, size_t length)
487487
{
488-
489-
ceph_assert(buffer && length == total_intended_len);
488+
ceph_assert(length == total_intended_len);
490489

491490
map<uint64_t,pair<bufferlist,uint64_t> >::reverse_iterator p = partial.rbegin();
492491
if (p == partial.rend())
493492
return;
494493

494+
ceph_assert(buffer);
495+
495496
uint64_t curr = length;
496497
uint64_t end = p->first + p->second.second;
497498
while (p != partial.rend()) {

src/test/librbd/test_librbd.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8683,8 +8683,12 @@ TEST_F(TestLibRBD, ZeroLengthWrite)
86838683
ASSERT_EQ(0, create_image(ioctx, name.c_str(), size, &order));
86848684
ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL));
86858685

8686-
char read_data[1];
8686+
const char data[] = "blah";
8687+
ASSERT_EQ(0, rbd_write(image, 0, 0, data));
8688+
ASSERT_EQ(0, rbd_write(image, 0, 0, (char*)0x123));
86878689
ASSERT_EQ(0, rbd_write(image, 0, 0, NULL));
8690+
8691+
char read_data[1];
86888692
ASSERT_EQ(1, rbd_read(image, 0, 1, read_data));
86898693
ASSERT_EQ('\0', read_data[0]);
86908694

@@ -8736,6 +8740,8 @@ TEST_F(TestLibRBD, ZeroLengthRead)
87368740

87378741
char read_data[1];
87388742
ASSERT_EQ(0, rbd_read(image, 0, 0, read_data));
8743+
ASSERT_EQ(0, rbd_read(image, 0, 0, (char*)0x123));
8744+
ASSERT_EQ(0, rbd_read(image, 0, 0, NULL));
87398745

87408746
ASSERT_EQ(0, rbd_close(image));
87418747

0 commit comments

Comments
 (0)