Skip to content

Conversation

@Crypt-iQ
Copy link
Contributor

@Crypt-iQ Crypt-iQ commented May 10, 2021

nMessageSize is uint32_t and is set to -1. This will warn with -fsanitize=implicit-integer-sign-change when V1TransportDeserializer calls into the ctor. This pull initializes nMessageSize to numeric_limits<uint32_t>::max() instead and removes the ubsan suppression.

@fanquake fanquake added the P2P label May 10, 2021
src/protocol.cpp Outdated
memset(pchMessageStart, 0, MESSAGE_START_SIZE);
memset(pchCommand, 0, sizeof(pchCommand));
nMessageSize = -1;
nMessageSize = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Good catch. Haven't checked if changing from -1 to 0 has no impact (but I guess not), but if we're changing this anyway, maybe move initialization to the class definition

class CMessageHeader
{
⋮ 
    uint32_t nMessageSize{0};
⋮ 
}

Not sure if the same is possible for the arrays but that would be even better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I can tackle this in another PR, thanks for the suggestion

@maflcko
Copy link
Member

maflcko commented May 10, 2021

Please remove the suppression if the goal of this pull is to fix it

@practicalswift
Copy link
Contributor

practicalswift commented May 10, 2021

Concept ACK

Last time I checked (early April) this was the only remaining -fsanitize=integer warning in protocol.cpp. In other words you should be able to remove the suppression for protocol.cpp as part of this PR :)

To limit the scope of this PR and to guarantee preservation of current behaviour I would suggest keeping std::numeric_limits<uint32_t>::max() as the initial value. (Not claiming that changing to 0 would change behaviour: I haven't check.)

As laanwj mentioned in-class member initialization would be nice.

nMessageSize is uint32_t and is set to -1. This will warn with
-fsanitize=implicit-integer-sign-change.
@Crypt-iQ Crypt-iQ force-pushed the cmessageheader_signchange_05102021 branch from 1abc466 to 9c891b6 Compare May 11, 2021 15:23
@Crypt-iQ Crypt-iQ changed the title net: set nMessageSize to 0 in CMessageHeader ctor net: initialize nMessageSize to uint32_t max May 11, 2021
@Crypt-iQ Crypt-iQ force-pushed the cmessageheader_signchange_05102021 branch 2 times, most recently from 1abc466 to 9c891b6 Compare May 11, 2021 15:41
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Code review ACK 9c891b6.

Here or follow up it could even drop the constructor and ditch memset calls and just intialize arrays like char pchCommand[COMMAND_SIZE]{};

@laanwj
Copy link
Member

laanwj commented May 12, 2021

Code review ACK 9c891b6

Here or follow up it could even drop the constructor and ditch memset calls and just intialize arrays like char pchCommand[COMMAND_SIZE]{};

Agree, would be nice to do this, though I think this PR is good (and self-contained) as-is.

@laanwj laanwj merged commit 6b49d88 into bitcoin:master May 12, 2021
@Crypt-iQ Crypt-iQ deleted the cmessageheader_signchange_05102021 branch May 12, 2021 15:45
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 12, 2021
laanwj added a commit that referenced this pull request May 13, 2021
1c9255c refactor: Replace memset calls with array initialization (João Barbosa)

Pull request description:

  Follow up to #21905 (review).

ACKs for top commit:
  laanwj:
    re-ACK 1c9255c
  Crypt-iQ:
    Code review ACK 1c9255c

Tree-SHA512: 4b61dec2094f4781ef1c0427ee3bda3cfea12111274eebc7bc40a84f261d9c1681dd0860c57200bea2456588e44e8e0aecd18545c25f1f1250dd331ab7d05f28
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 13, 2021
…lization

1c9255c refactor: Replace memset calls with array initialization (João Barbosa)

Pull request description:

  Follow up to bitcoin#21905 (review).

ACKs for top commit:
  laanwj:
    re-ACK 1c9255c
  Crypt-iQ:
    Code review ACK 1c9255c

Tree-SHA512: 4b61dec2094f4781ef1c0427ee3bda3cfea12111274eebc7bc40a84f261d9c1681dd0860c57200bea2456588e44e8e0aecd18545c25f1f1250dd331ab7d05f28
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants