mbedtls icon indicating copy to clipboard operation
mbedtls copied to clipboard

Missing include stdlib.h and stdio.h in some platform configurations

Open gilles-peskine-arm opened this issue 9 months ago • 0 comments

In some configurations, we use platform functions without including the header that declares them. The exact set of configurations where this happens is probably hard to describe. Presumably, it's certain settings for the various MBEDTLS_PLATFORM_xxx options.

Workaround: include stdlib.h or stdio.h if needed from mbedtls/mbedtls_config.h, mbedtls/config.h, MBEDTLS_CONFIG_FILE or MBEDTLS_USER_CONFIG_FILE as applicable.


Reported in https://github.com/openthread/openthread/pull/10263#discussion_r1605313884 with Mbed TLS 2.28.7. I have no reason to think that 3.x would do better here.

Users/runner/work/openthread/openthread/third_party/mbedtls/repo/library/memory_buffer_alloc.c:246:9: error: implicitly declaring library function 'exit' with type 'void (int) __attribute__((noreturn))' [-Werror,-Wimplicit-function-declaration]
        mbedtls_exit(1);
        ^
/Users/runner/work/openthread/openthread/third_party/mbedtls/repo/include/mbedtls/platform.h:322:24: note: expanded from macro 'mbedtls_exit'
#define mbedtls_exit   exit
                       ^
/Users/runner/work/openthread/openthread/third_party/mbedtls/repo/library/memory_buffer_alloc.c:246:9: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit'
/Users/runner/work/openthread/openthread/third_party/mbedtls/repo/include/mbedtls/platform.h:322:24: note: expanded from macro 'mbedtls_exit'
#define mbedtls_exit   exit

The presumed relevant part of the configuration is (starting from a blank configuration, not from the default):

#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
#define MBEDTLS_NO_PLATFORM_ENTROPY
#define MBEDTLS_PLATFORM_C
#define MBEDTLS_PLATFORM_MEMORY
#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
#define MBEDTLS_MEMORY_BUFFER_ALLOC_C

Goals of this task:

  • Identify in which configurations the build is broken.
  • Add at least one all.sh component with a build that's currently broken.
  • Fix all problems of this kind that you can find (missing inclusion of stdlib.h or stdio.h).
  • Do not break the build on systems where it currently works and that don't have stdlib.h or stdio.h.

gilles-peskine-arm avatar May 17 '24 17:05 gilles-peskine-arm