Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/bufferlist: Fixing corruption on ptr(ptr&& p) #7779

Closed

Conversation

ErwanAliasr1
Copy link
Contributor

The bufferlist is trying to compare two strings by doing :
str.compare(0, str.size(), ptr.c_str())

This have been introduced recently in commit 41c3dc2.

The issue in that test is not providing the amount of char to compare but only
the size of 'str'.

As a result, it does compare a null-terminated string (str) with a
non-terminated buffer (ptr).

The issue was discoverd by having on a test where

  • str="XXXXXXXXXXXXXXXXX"
    but
  • ptr="XXXXXXXXXXXXXXXXXriptor".

The associated assertion failed and broke the test.

This patch is fixing the issue by using the memcmp() call as per 'ptr(const
ptr& p, unsigned o, unsigned l)' test.

The simple solution is to test the buffer at the byte level and only for the
n-bytes of the initial string.

That change makes the test passing.

Regarding the initial code, that's pretty a big chance that no-one hit that
before.

Signed-off-by: Erwan Velu erwan@redhat.com

@cbodley
Copy link
Contributor

cbodley commented Feb 24, 2016

👍

@yuyuyu101
Copy link
Member

LGTM

@tchaikov
Copy link
Contributor

👍

@ghost ghost self-assigned this Feb 24, 2016
@ErwanAliasr1
Copy link
Contributor Author

Should I do something to get it merged ?

@tchaikov
Copy link
Contributor

@ErwanAliasr1 no, we just need to run it with a rados qa test.

@ghost
Copy link

ghost commented Feb 26, 2016

@ErwanAliasr1 now that make check has been fixed, it would help if you could rebase and repush, just for the sake of having it clean. The "needs-qa" means that a run of teuthology tests need to happen to verify there is no regression. When a commit touches a central part of the Ceph code, this is a necessary precaution. It usually takes from one to four weeks for that verification to happen. So you can add a reminder to ping in four weeks from now if nothing else happens. Other than this, you're good :-)

The bufferlist is trying to compare two strings by doing :
    str.compare(0, str.size(), ptr.c_str())

This have been introduced recently in commit 41c3dc2.

The issue in that test is not providing the amount of char to compare but only
the size of 'str'.

As a result, it does compare a null-terminated string (str) with a
non-terminated buffer (ptr).

The issue was discoverd by having on a test where
 - str="XXXXXXXXXXXXXXXXX"
but
 - ptr="XXXXXXXXXXXXXXXXXriptor".

The associated assertion failed and broke the test.

This patch is fixing the issue by using the memcmp() call as per 'ptr(const
ptr& p, unsigned o, unsigned l)' test.

The simple solution is to test the buffer at the byte level and only for the
n-bytes of the initial string.

That change makes the test passing.

Regarding the initial code, that's pretty a big chance that no-one hit that
before.

Signed-off-by: Erwan Velu <erwan@redhat.com>
@ErwanAliasr1
Copy link
Contributor Author

@dachary rebased & repushed.

@liewegas
Copy link
Member

liewegas commented Mar 3, 2016

already fixed by 7723d29

@liewegas liewegas closed this Mar 3, 2016
@ErwanAliasr1
Copy link
Contributor Author

@liewegas : In this commit,if ptr.length() is shorter than str.size() then we do pass while it's incorrect :(

@liewegas
Copy link
Member

liewegas commented Mar 7, 2016

This std::string compare variant we switched to (int compare (size_t pos, size_t len, const char* s, size_t n) const) in commit 7723d29 does this, right?

@ErwanAliasr1
Copy link
Contributor Author

I pushed #7955 to explain & solve the issue I see with this way to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants