-
Notifications
You must be signed in to change notification settings - Fork 267
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
Cast to void #121
base: master
Are you sure you want to change the base?
Cast to void #121
Conversation
Prevent warnings from popping up in GCC >= 8.1
@@ -76,7 +76,7 @@ struct UTPSocketKey { | |||
uint32 recv_id; // "conn_seed", "conn_id" | |||
|
|||
UTPSocketKey(const PackedSockAddr& _addr, uint32 _recv_id) { | |||
memset(this, 0, sizeof(*this)); | |||
memset(static_cast<void*>(this), 0, sizeof(*this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about removing this line to resolve the problem? This structure contains two members, both of which are initialized in this constructor in statements immediately after this statement, so the memset call here seems unnecessary. I would hope that code isn't depending that any inter-member space in this structure be initialized to zeroes. Could even change the following assignments to be within an initialization list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not experienced in C or C++, so I started reading around memset
and usage in zeroing out structures. Seems like this is done intentionally, so that we don't leak information about the structure through the network. Since it's a bit controversial, I'd prefer if we don't remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been a number of years now, but if I recall correctly this line was added to try to work around a bug in the hash table implementation which was later fixed by Art. It may not be needed now, but you'll probably want to do a bunch of QA testing first to confirm that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this structure is passed in its entirety via the network, I could see clearing it out to avoid disclosure. Either for this reason, or for the case that this was done to avoid a hash table bug, I'd like to see a comment that explains this inserted before the memset() call if the memset() line is retained, since this would be non-obvious valuable information that could easily be lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rmcdonald / @mct Could you ping someone who worked on this to add the comment about the reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my recollection is that the hash table implementation used in uTorrent (not sure if it's still used in libutp) hashes the storage bytes of the key, and compares them with memcmp()
. In other words, the padding bits are used by the hash table (or at least "were", it may have changed). I would think that's at least the reason for this call to memset()
.
As an alternative fix for this, the hash table could have an assert like this:
static_assert(std::has_unique_object_representations_v<Key>, "Key type may not have padding bits")
Then it would be safe to remove the memset()
here (afaict).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these are some places in the code where we have hints (as far as I could understand) that there might be some reasoning behind the memset
.
https://github.com/bittorrent/libutp/blob/master/utp_hash.h#L43-L75
https://github.com/bittorrent/libutp/blob/master/utp_hash.cpp#L113-L118
I don't know how to test this properly and would appreciate any help.
Apologies for breaking the silence 🙊. Is the PR good enough to be merged as it is without removing the line? |
Hi again! I was going through the list of my PRs and I noticed this one hasn't been active for quite some time. Personally, I find warnings in my build logs not pretty, and this PR addresses that issue. Would it be able to get this merged, or should I close it and leave the warnings? |
Hi, what is the status of this PR pls ? |
I would approve a PR that removes the memset and adds the static_assert I suggested earlier. nut I don’t have privileges to merge |
Any update on this? Would anyone be willing to merge this? |
I do not think this proposed patch is a good solution to the GCC warning. The warning is right, this patch just silences it instead of fixing the code. |
Prevent warnings from popping up in GCC >= 8.1
Resolved like in this issue: oneapi-src/oneTBB#54