Skip to content

[tests] Fix incorrect memory_cleanse(…) call in crypto_tests.cpp#10912

Merged
laanwj merged 1 commit intobitcoin:masterfrom
practicalswift:arrays-are-not-pointers
Jul 26, 2017
Merged

[tests] Fix incorrect memory_cleanse(…) call in crypto_tests.cpp#10912
laanwj merged 1 commit intobitcoin:masterfrom
practicalswift:arrays-are-not-pointers

Conversation

@practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Jul 22, 2017

chKey and chIV are pointers, not arrays :-)

Probably the result of copy-pasting of old code where the code was operating on arrays instead of pointers.

If I'm reading the code correctly the absence/presence of these memory_cleanse(…) calls won't alter the outcome of the test in question (TestPassphraseSingle) even if fixed. Therefore removing.

@fanquake fanquake added the Tests label Jul 22, 2017
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the sizeof to WALLET_CRYPTO_KEY_SIZE, and WALLET_CRYPTO_IV_SIZE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonasschnelli Yes, that is the correct fix if we want to keep the memory_cleanse(…)-calls. Do we? :-) If so, I'll fix them!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care that much. I personably would try to keep it even if cleaning memory is pointless because I generally follow "test more is better"-approach.

@jonasschnelli
Copy link
Contributor

jonasschnelli commented Jul 24, 2017

Nice catch!
AFAIK this is the only place where (we intended) to test memory_cleanse. Maybe keep it and switch the sizeof's to the correct constants?

@sipa
Copy link
Member

sipa commented Jul 24, 2017

Having memory_cleanse in a test seems pointless.

@practicalswift
Copy link
Contributor Author

Perhaps memory_cleanse deserves a dedicated test (a subject for another PR)? :-)

If so I'll leave this PR as-is.

@jonasschnelli
Copy link
Contributor

Agree with a dedicated test.
@sipa is right that cleaning memory in test is pointless, although I think it makes sense to test the memory_cleanse function (to eventually make sure compiler doesn't optimise out the cleanse [volatile] function)?

@sipa
Copy link
Member

sipa commented Jul 24, 2017

Testing more is better, but I think this code is not testing more. If the memory_cleanse would somehow fail to do its job, I don't think this would cause any test to fail? (I haven't looked closely, please correct me if I'm wrong)

@jonasschnelli
Copy link
Contributor

If the memory_cleanse would somehow fail to do its job, I don't think this would cause any test to fail?

Yes. We should have a dedicated test for memory_cleanse then.
Just executing the code has only little advantages (crashes/exceptions will be detected, memory leaks when running with valgrind, etc.).

@practicalswift practicalswift force-pushed the arrays-are-not-pointers branch from 5b8fddd to 17a1f63 Compare July 24, 2017 09:10
@practicalswift
Copy link
Contributor Author

I've now updated the PR: now calling memory_cleanse(…) with the expected args.

@jonasschnelli
Copy link
Contributor

utACK 17a1f639c906a14e02ac03b51b7e030f3f47a86c

@TheBlueMatt
Copy link
Contributor

utACK. Yes, lets actually /test/ memory_cleanse at some point.

@maflcko
Copy link
Member

maflcko commented Jul 25, 2017

Please amend the commit message/pull request body and pull title.

@practicalswift practicalswift changed the title [tests] Remove incorrect memory_cleanse(…) call in crypto_tests.cpp [tests] Fix incorrect memory_cleanse(…) call in crypto_tests.cpp Jul 25, 2017
@practicalswift practicalswift force-pushed the arrays-are-not-pointers branch from 17a1f63 to 8ca59d8 Compare July 25, 2017 22:05
@practicalswift
Copy link
Contributor Author

@MarcoFalke Done! :-)

chKey and chIV are pointers, not arrays :-)

Probably the result of copy-pasting of old code which was
operating on arrays instead of pointers.
@practicalswift practicalswift force-pushed the arrays-are-not-pointers branch from 8ca59d8 to 065039d Compare July 25, 2017 23:49
@laanwj laanwj merged commit 065039d into bitcoin:master Jul 26, 2017
laanwj added a commit that referenced this pull request Jul 26, 2017
…tests.cpp

065039d [tests] Fix incorrect memory_cleanse(…) call in crypto_tests.cpp (practicalswift)

Pull request description:

  `chKey` and `chIV` are pointers, not arrays :-)

  Probably the result of copy-pasting of old code where the code was operating on arrays instead of pointers.

  If I'm reading the code correctly the absence/presence of these `memory_cleanse(…)` calls won't alter the outcome of the test in question (`TestPassphraseSingle`) even if fixed. Therefore removing.

Tree-SHA512: a053b2817bedf6ef889744e546ce9a0f165dee94aef6850d9d6a6bb05b0018789597371ecf154a4aec8588c0ef5626ef08c23c35e35927f6b0497b5f086146fe
@laanwj
Copy link
Member

laanwj commented Jul 26, 2017

Apparently this tests nothing, if this error was not detected!

But it's clear that the new code is what the intention was so meh-ACK.

@maflcko
Copy link
Member

maflcko commented Jul 30, 2017

post mege utACK 065039d

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Aug 2, 2019
…crypto_tests.cpp

065039d [tests] Fix incorrect memory_cleanse(…) call in crypto_tests.cpp (practicalswift)

Pull request description:

  `chKey` and `chIV` are pointers, not arrays :-)

  Probably the result of copy-pasting of old code where the code was operating on arrays instead of pointers.

  If I'm reading the code correctly the absence/presence of these `memory_cleanse(…)` calls won't alter the outcome of the test in question (`TestPassphraseSingle`) even if fixed. Therefore removing.

Tree-SHA512: a053b2817bedf6ef889744e546ce9a0f165dee94aef6850d9d6a6bb05b0018789597371ecf154a4aec8588c0ef5626ef08c23c35e35927f6b0497b5f086146fe
@practicalswift practicalswift deleted the arrays-are-not-pointers branch April 10, 2021 19:32
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants