-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
@@ -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)); |
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.
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));
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.
Overlooked that. I made some bad experiences with the variable solution "oops that was a pointer" ;-).
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.
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. :-)
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.
Fixed
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.
Well than I would like to be consistent with gnrc_sock_udp
where I also used size notation ;-).
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.
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)); |
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.
Please consider my suggestion about using a variable instead of a type. This bug wouldn't exist if we did it that way.
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.
And, hmm, that was a quick fix. It compiled, so it must be correct ? ;-)
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.
Well than I would like to be consistent with gnrc_sock_udp where I also used size notation ;-).
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.
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.
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 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.
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'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
The type in the `sizeof()` is just plain wrong. This fixes it.
252fee8
to
653e362
Compare
Backport provided in #6098 |
The type in the
sizeof()
is just plain wrong. This fixes it.