Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
580 stars 738 forks source link

Avoid crash in http_e2e due to no string function for enum #2582

Closed ewertons closed 4 months ago

ewertons commented 4 months ago
# Checklist - [x] I have read the [contribution guidelines] (https://github.com/Azure/azure-iot-sdk-c/blob/main/.github/CONTRIBUTING.md). - [ ] I added or modified the existing tests to cover the change (we do not allow our test coverage to go down). - If this is a modification that impacts the behavior of a public API - [ ] I edited the corresponding document in the `devdoc` folder and added or modified requirements. - I submitted this PR against the correct branch: - [x] This pull-request is submitted against the `main` branch. - [x] I have merged the latest `main` branch prior to submission and re-merged as needed after I took any feedback. - [x] I have squashed my changes into one with a clear description of the change. # Reference/Link to the issue solved with this PR (if any) # Description of the problem

IOTHUB_CLIENT_CONFIRMATION_RESULT is not defined in the iothubclient_http_e2e.c, causing MU_ENUM_TO_STRING to return NULL and strlen (stack below) to SEGFAULT, since as per spec NULL arg to strlen has undefined behavior (thus assume the worst).

2024-02-21T22:23:23.0396823Z 240: ==9665== Process terminating with default action of signal 11 (SIGSEGV)
2024-02-21T22:23:23.0397379Z 240: ==9665==  Access not within mapped region at address 0x3
2024-02-21T22:23:23.0398384Z 240: ==9665==    at 0x48507D6: strlen (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_drd-amd64-linux.so)
2024-02-21T22:23:23.0399076Z 240: ==9665==    by 0x4E5DD14: __vfprintf_internal (vfprintf-internal.c:1688)
2024-02-21T22:23:23.0399629Z 240: ==9665==    by 0x4E70F99: __vsnprintf_internal (vsnprintf.c:114)
2024-02-21T22:23:23.0400154Z 240: ==9665==    by 0x119C0F: ctest_vsprintf_char (ctest.c:502)
2024-02-21T22:23:23.0400660Z 240: ==9665==    by 0x119CEF: ctest_sprintf_char (ctest.c:520)
2024-02-21T22:23:23.0401182Z 240: ==9665==    by 0x116634: IoTHub_HTTP_SendEvent_Shared_e2e (iothubclient_http_e2e.c:707)
2024-02-21T22:23:23.0401907Z 240: ==9665==    by 0x1191D0: RunTests (ctest.c:158)
2024-02-21T22:23:23.0402546Z 240: ==9665==    by 0x1189F8: main (main.c:9)

Description of the solution

Define the enum in the test module, which then defines the string functions for it.