Files
libcoap/tests/testdriver.c
T
Alejandro Pacheco 92fc71e908 coap_block.c: Use get_func wherever a request body is added
For a request set up with coap_add_data_large_request_app(), the data
is provided by the application's get_func and there is no data pointer.
Three places still took the body from that NULL pointer, so
coap_add_data() was passed a NULL pointer:

- check_freshness(), re-sending the next block with the Echo option
  from a 4.01 response.
- coap_cancel_observe_lkd(), re-adding the observe request's body to
  the cancel request.
- coap_add_data_large_internal(), when the application sets a Block1
  option with a non-zero block number to send a single block.

Use get_func in all of these, as the other places that send a block of
an lg_xmit already do. The single block and the whole-body cases now
share add_get_func_data(), which also checks the allocation and no
longer leaks the buffer when get_func fails.

Add unit tests.
2026-10-16 14:14:20 +01:00

71 lines
1.7 KiB
C

/* libcoap unit tests
*
* Copyright (C) 2012-2026 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
#include <stdio.h>
#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>
#include "test_common.h"
#include "test_block.h"
#include "test_uri.h"
#include "test_encode.h"
#include "test_options.h"
#include "test_pdu.h"
#include "test_error_response.h"
#include "test_session.h"
#include "test_sendqueue.h"
#include "test_wellknown.h"
#include "test_tls.h"
#if COAP_OSCORE_SUPPORT && COAP_SERVER_SUPPORT
#include "test_oscore.h"
#endif /* COAP_OSCORE_SUPPORT && COAP_CLIENT_SUPPORT */
int
main(int argc COAP_UNUSED, char **argv COAP_UNUSED) {
CU_ErrorCode result;
CU_BasicRunMode run_mode = CU_BRM_VERBOSE;
unsigned int failed;
if (CU_initialize_registry() != CUE_SUCCESS) {
fprintf(stderr, "E: test framework initialization failed\n");
return -2;
}
coap_startup();
t_init_uri_tests();
t_init_encode_tests();
t_init_option_tests();
t_init_pdu_tests();
t_init_error_response_tests();
#if COAP_CLIENT_SUPPORT
t_init_session_tests();
t_init_sendqueue_tests();
t_init_block_tests();
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT && COAP_CLIENT_SUPPORT
t_init_wellknown_tests();
#endif /* COAP_SERVER_SUPPORT && COAP_CLIENT_SUPPORT */
t_init_tls_tests();
#if COAP_OSCORE_SUPPORT && COAP_SERVER_SUPPORT
t_init_oscore_tests();
#endif /* COAP_OSCORE_SUPPORT && COAP_CLIENT_SUPPORT */
CU_basic_set_mode(run_mode);
result = CU_basic_run_tests();
failed = CU_get_number_of_failures();
CU_cleanup_registry();
coap_cleanup();
if (failed)
exit(1);
return result;
}