cryptonote_basic: fix add_extra_nonce_to_tx_extra() length#10220
cryptonote_basic: fix add_extra_nonce_to_tx_extra() length#10220tobtoht merged 1 commit intomonero-project:masterfrom
Conversation
c9d3df2 to
980edf9
Compare
|
Unit test failure is unrelated. |
980edf9 to
b3e8ff8
Compare
|
Fixed test cases up and added tests for |
| { | ||
| extra = extra_prefix; | ||
| nonce.resize(nonce_size); | ||
| memset(&nonce[0], '%', nonce.size()); |
There was a problem hiding this comment.
For the record, this probably is fine in practice since operator[]() will return some garbage pointer, and memset() is passed a length of 0, but you're absolutely right that operator[]() when pos < size() is false triggers UB (At least until C++26 with a "hardened implementation", under which scenario it becomes a contract violation, not UB).
Will update
| subtest_varint_byte_size_for_single_value(1, n); | ||
| } | ||
|
|
||
| for (T n = 128; n < 255; ++n) |
There was a problem hiding this comment.
But be careful about type bounds to not make it an infinite loop. So (n <= 255) && n is better, to be sure that it doesn't get stuck.
There was a problem hiding this comment.
Actually nevermind, I see that you check 255 and 65535 separately further down in the code.
| subtest_varint_byte_size_for_single_value(2, n); | ||
| } | ||
|
|
||
| for (T n = 16384; n < 65535; ++n) |
b3e8ff8 to
5c56c82
Compare
Reviewed-by: selsta <selsta@sent.at> Reviewed-by: SChernykh
5c56c82 to
2eed71e
Compare
|
Sorry, I made one more change: I added an |
Serialization/deserialization code in$[128, 256)$ , these two sections diverge. This commit amends
tx_extra.htreats the nonce length as a varint, butcryptonote::add_extra_nonce_to_tx_extra()writes the nonce length as a raw unsigned 8-bit integer. For nonce sizes incryptonote::add_extra_nonce_to_tx_extra()to match the serialization code.Issue identified by the Monero Oxide project and reporters.