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

gnrc_sock_ip: fix memcpy()/memset() sizeof-type #6083

Merged
merged 1 commit into from
Nov 9, 2016

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Nov 8, 2016

The type in the sizeof() is just plain wrong. This fixes it.

@miri64 miri64 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking GNRC CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch labels Nov 8, 2016
@miri64 miri64 added this to the Release 2016.10 milestone Nov 8, 2016
@@ -41,17 +41,17 @@ int sock_ip_create(sock_ip_t *sock, const sock_ip_ep_t *local,
if (gnrc_af_not_supported(local->family)) {
return -EAFNOSUPPORT;
}
memcpy(&sock->local, local, sizeof(sock_ip_t));
memcpy(&sock->local, local, sizeof(sock_ip_ep_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

In case like this I prefer to use the variable instead of the type.

memcpy(&sock->local, local, sizeof(sock->local));

And why is the memset before this not changed? I see

memset(&sock->local, 0, sizeof(sock_ip_t));

Copy link
Member Author

Choose a reason for hiding this comment

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

Overlooked that. I made some bad experiences with the variable solution "oops that was a pointer" ;-).

Copy link
Contributor

Choose a reason for hiding this comment

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

Take a look at all the memset's and memcpy's. We could use some consistency.

Yes, of course you must know what the variable is. But hey, we're programmers. We know. :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member Author

Choose a reason for hiding this comment

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

Well than I would like to be consistent with gnrc_sock_udp where I also used size notation ;-).

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we not discuss minor style questions in a hotfix for the release, please?

@@ -36,7 +36,7 @@ int sock_ip_create(sock_ip_t *sock, const sock_ip_ep_t *local,
(local->netif != remote->netif)) {
return -EINVAL;
}
memset(&sock->local, 0, sizeof(sock_ip_t));
memset(&sock->local, 0, sizeof(sock_ip_ep_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider my suggestion about using a variable instead of a type. This bug wouldn't exist if we did it that way.

Copy link
Contributor

Choose a reason for hiding this comment

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

And, hmm, that was a quick fix. It compiled, so it must be correct ? ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Well than I would like to be consistent with gnrc_sock_udp where I also used size notation ;-).

Copy link
Member Author

Choose a reason for hiding this comment

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

And, hmm, that was a quick fix. It compiled, so it must be correct ? ;-)

Nope, tested with tests/gnrc_sock_ip on IoT-LAB, but since this and the following variable were initialized with 0 it fell through.

Copy link
Member

Choose a reason for hiding this comment

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

I have mixed feelings whether to use the type or the instance as a parameter for sizeof here. I understand @keestux's rationale, but I also think that using the type makes the developer aware of how much memory is actually initialized/copied.

However, I totally agree with @miri64 that this is out of scope for this PR.

Copy link
Member

@OlegHahm OlegHahm left a comment

Choose a reason for hiding this comment

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

I'm not able to reproduce a crash on native or samr21-xpro. Strange enough: not even valgrind is complaining.

However, the diff looks valid and it doesn't crash with this PR merged, either: ACK

@OlegHahm OlegHahm added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 9, 2016
The type in the `sizeof()` is just plain wrong. This fixes it.
@miri64 miri64 force-pushed the gnrc_sock_ip/fix/fix-memcpy-type branch from 252fee8 to 653e362 Compare November 9, 2016 20:24
@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 9, 2016
@miri64
Copy link
Member Author

miri64 commented Nov 9, 2016

Backport provided in #6098

@miri64 miri64 removed the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Nov 9, 2016
@miri64 miri64 merged commit 9ce5a5b into RIOT-OS:master Nov 9, 2016
@miri64 miri64 deleted the gnrc_sock_ip/fix/fix-memcpy-type branch November 9, 2016 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants