-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Ethernet: Fix out of bounds memset on reset DHCP lease #6337
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
Conversation
Looking at the comment, this memset is intentionally out-of-bounds, so it doesn't just reset the localIP variable, but also the subsequent variables. This is of course fairly fragile (and confusing), so a better approach might be to store all lease-related variables that need to be reset into a struct and then memset the struct instead of separate variables. |
Oh, confusing indeed. Anything in particular wrong with memsetting the individual ones? |
Performance (time and code space) I suspect, but that's not really a compelling reason for something that happens as rarely as this. So splitting in different memsets would indeed be a good approach. Care to try and see how much extra flash that takes? Perhaps gcc surprises us and joins them together? :-) |
Maybe a more self-explanatory code would be a good idea, like memset(&_dhcpLocalIp, 0, (char*)(&_dhcpLeaseTime) - (char*)(&_dhcpLocalIp)); or at least a comment clarifying that 5 members are being cleared at once. |
Ethernet has a extra repo, see: https://github.com/arduino-libraries/Ethernet I reported this already: arduino-libraries/Ethernet#45 Memset should be used for every variable, the actual code is a nightmare. |
@matthijskooijman the idea is to remove the library from the main repo once it has no PR on it (or they have been moved to the new repo). Ironically, it was easier to move SAM folder than Ethernet library 😄 |
@facchinm, but now that a separate repo exists and the library is still included in this repo, any merged PRs in this repo will have to be manually ported over to the separate repo, right (and vice versa as well)? Wouldn't it make sense to just remove the library from this repo? You would need to manually port the PRs over to the other repo, but you need to do that anyway. And it prevents new PRs from appearing here. Or am I missing something here? |
No, you are not missing anything 😄 We only need to allocate some time to move everything to the new repo and then we can simply delete the folder here. |
@facchinm, but now that a separate repo exists and the library is still included in this repo, any merged PRs in this repo will have to be manually ported over to the separate repo, right (and vice versa as well)? Wouldn't it make sense to just remove the library from this repo? You would need to manually port the PRs over to the other repo, but you need to do that anyway. And it prevents new PRs from appearing here. Or am I missing something here? |
No description provided.