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

use calloc for new_interface_server #14342

Merged
merged 2 commits into from
Mar 12, 2021

Conversation

JojoS62
Copy link
Contributor

@JojoS62 JojoS62 commented Feb 24, 2021

malloc left garbage in the structure, dns IPs were filled with random content

Summary of changes

PR for #14292
When creating a new dns server interfaces, the server list did contain garbage because of mem_malloc function. Replacing by mem_calloc() initialises with zeros which is IP_ADDR_ANY.

Impact of changes

bugfix

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[x] Tests / results supplied as part of this PR

Test program is given in #14292

Reviewers

@geky

malloc left garbage in the structure, dns IPs were filled with random content
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Feb 24, 2021
@ciarmcom ciarmcom requested review from geky and a team February 24, 2021 20:00
@ciarmcom
Copy link
Member

@JojoS62, thank you for your changes.
@geky @ARMmbed/mbed-os-maintainers please review.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 25, 2021

Was this fixed upstream (newer lwip version) ?
Shall we add a test to catch this?

@JojoS62
Copy link
Contributor Author

JojoS62 commented Feb 25, 2021

@0xc0170 you're right, this is in the lwIP core. As far as I can see, Mbed uses already the most recent lwIP version 2.1.2 from 2018.
As a workaround, maybe the dns table could be cleared in connectivity/lwipstack/source/LWIPInterface.cpp.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 25, 2021

It might be worth creating a bug report to lwipstack or as you wrote fix it on our side (did we miss it and we should take care of it?).

@ARMmbed/mbed-os-connectivity will know better

@JojoS62
Copy link
Contributor Author

JojoS62 commented Feb 25, 2021

the list of issues in lwIP has grown since 2018, looks like there is no real progress at the moment, or the intervalls for updates are really long. I'm not sure about the priority of this issue, the 2nd DNS is a random value and it should happen very very seldom that you hit a fake DNS for your address resolution.

edit:
it looks like dns_add_interface_server() is a Mbed extension, I can't find this in the original lwIP source code.
This function was added for multihoming in 42b5680 after updating to lwIP 2.1.2

@ciarmcom ciarmcom added the stale Stale Pull Request label Feb 28, 2021
@ciarmcom
Copy link
Member

This pull request has automatically been marked as stale because it has had no recent activity. @geky, @ARMmbed/mbed-os-maintainers, @ARMmbed/mbed-os-connectivity, please complete review of the changes to move the PR forward. Thank you for your contributions.

@ithinuel
Copy link
Member

ithinuel commented Mar 1, 2021

Replacing by mem_calloc() initialises with zeros which is IP_ADDR_ANY.

Hello, in order to reduce the risk of regression, it would be better to keep mem_malloc and set the field to what we really want them IP_ADDR_ANY in this case.

It may be a lucky coincidence that 0 happens to be what we want. Future versions of LWIP may change the value of that flag and silently break again what is fixed by this PR.

@JojoS62
Copy link
Contributor Author

JojoS62 commented Mar 1, 2021

With mem_alloc, the whole structure gets random garbage. Filling the fields with valid values is ok also, but when the structure is extended you will have again garbage and you have to touch this code again.
I think clearing the memory is the better solution.

and again, this is not lwip code, it is a Mbed extension.

@ithinuel
Copy link
Member

ithinuel commented Mar 1, 2021

Indeed, common good practices are also to provide an initializer, either as a macro, a constant object or a function that does that for us.

I had a glance at the upstream LWIP and it seems like either this is some legacy code that has been removed or something specific to mbed's fork of lwip.
Either way, since this is actually inside LWIP implementation and that our fork of LWIP seems to have diverged a lot from the upstream, I guess it is fine to use calloc as we are unlikely to "upgrade".

Also, since this struct is never used outside of that very specific file, I would recommend move the struct's definition from the header to the c file it is used and provide a proper initialized to be later used in the related function.

@0xc0170 0xc0170 removed the stale Stale Pull Request label Mar 2, 2021
@ciarmcom ciarmcom added the stale Stale Pull Request label Mar 2, 2021
use ip_addr function to initialize dns_add_interface_server
Copy link
Member

@ithinuel ithinuel left a comment

Choose a reason for hiding this comment

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

LGTM

Note: I'm not part of @ARMmbed/mbed-os-connectivity so my approval only engages myself.

@ciarmcom ciarmcom removed the stale Stale Pull Request label Mar 2, 2021
@0xc0170
Copy link
Contributor

0xc0170 commented Mar 11, 2021

CI started

@mergify mergify bot added needs: CI and removed needs: review labels Mar 11, 2021
@mbed-ci
Copy link

mbed-ci commented Mar 11, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170 0xc0170 merged commit 6aef1af into ARMmbed:master Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants