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

Fix: casts between mbed::SocketAdrress * and struct sockaddr * cause memory overwrites due to different memory size and layout #8

Merged
merged 5 commits into from
Jul 17, 2024

Conversation

aentinger
Copy link
Collaborator

OPC/UA

struct sockaddr {
    SocketAddress ai;
};

struct addrinfo {
    SocketAddress ai;
    int     ai_flags;
    int     ai_family;
    int     ai_socktype;
    int     ai_protocol;
    size_t  ai_addrlen;
    struct  sockaddr *ai_addr;
    char    *ai_canonname;     /* canonical name */
    struct  addrinfo *ai_next; /* this struct can form a linked list */
};

MBED: SocketAddress

…dr *" caus memory overwrites in random locations as the size of those structures are not the same.
…or the previous code version too but has been ignored.
@aentinger aentinger added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Jul 16, 2024
@aentinger aentinger requested a review from facchinm July 16, 2024 05:47
@aentinger aentinger self-assigned this Jul 16, 2024
@arduino-libraries arduino-libraries deleted a comment from github-actions bot Jul 16, 2024
@arduino-libraries arduino-libraries deleted a comment from github-actions bot Jul 16, 2024
@aentinger
Copy link
Collaborator Author

Hi @facchinm ☕ 👋

auto rc = NetworkInterface::get_default_instance()->getaddrinfo(hostname, &mbed_hints, &mbed_res);

fails with NSAPI_ERROR_DNS_FAILURE (-3009) and has done so even before this PR.

The difference to before is that the return value of the function was previously not evaluated and always a result of 127.0.0.1 returned.

5204ec4 is a very quick fix that returns the previous functionality (no DNS lookup, assume 127.0.0.1) - however this is not desirable for the long run.

Do you have any idea what could be causing this issue (or a possible resolution)?

@aentinger aentinger merged commit 1c007bf into main Jul 17, 2024
4 checks passed
@aentinger aentinger deleted the fix/memory-overwrite branch July 17, 2024 03:55
Copy link

Memory usage change @ a4cf7ab

Board flash % RAM for global variables %
arduino:mbed_opta:opta 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/opcua_server
flash
% examples/opcua_server
RAM for global variables
%
arduino:mbed_opta:opta 0 0.0 0 0.0
Click for full report CSV
Board,examples/opcua_server<br>flash,%,examples/opcua_server<br>RAM for global variables,%
arduino:mbed_opta:opta,0,0.0,0,0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant