diff --git a/examples/coap-client.c b/examples/coap-client.c index 14565243..18b6777f 100644 --- a/examples/coap-client.c +++ b/examples/coap-client.c @@ -661,7 +661,7 @@ cmdline_content_type(char *arg, uint16_t key) { coap_optlist_t *node; unsigned char i; uint16_t value; - uint8_t buf[2]; + uint8_t buf[4]; if (isdigit((int)arg[0])) { value = atoi(arg); diff --git a/examples/coap-server.c b/examples/coap-server.c index e6ba08c4..f4e1351a 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -302,11 +302,11 @@ hnd_get_fetch_time(coap_resource_t *resource, if (code == COAP_REQUEST_CODE_GET && query != NULL && coap_string_equal(query, ticks)) { /* parameter is in query, output ticks */ - len = snprintf((char *)buf, sizeof(buf), "%u", (unsigned int)now); + len = snprintf((char *)buf, sizeof(buf), "%" PRIi64, (int64_t)now); } else if (code == COAP_REQUEST_CODE_FETCH && size == ticks->length && memcmp(data, ticks->s, ticks->length) == 0) { /* parameter is in data, output ticks */ - len = snprintf((char *)buf, sizeof(buf), "%u", (unsigned int)now); + len = snprintf((char *)buf, sizeof(buf), "%" PRIi64, (int64_t)now); } else { /* output human-readable time */ struct tm *tmp; tmp = gmtime(&now); diff --git a/src/coap_subscribe.c b/src/coap_subscribe.c index 862bd7fe..6a3d9608 100644 --- a/src/coap_subscribe.c +++ b/src/coap_subscribe.c @@ -72,7 +72,7 @@ coap_persist_observe_add(coap_context_t *context, coap_subscription_t *s; coap_endpoint_t *ep; - if (e_listen_addr == NULL || s_addr_info == NULL || packet == NULL) + if (e_listen_addr == NULL || s_addr_info == NULL || raw_packet == NULL) return NULL; /* Will be creating a local 'open' session */ @@ -310,6 +310,9 @@ coap_op_observe_read(FILE *fp, coap_subscription_t **observe_key, ssize_t size; coap_binary_t *scratch = NULL; + assert(fp && observe_key && e_proto && e_listen_addr && s_addr_info && + raw_packet && oscore_info); + *raw_packet = NULL; *oscore_info = NULL; @@ -331,8 +334,10 @@ coap_op_observe_read(FILE *fp, coap_subscription_t **observe_key, if (fread(scratch->s, scratch->length, 1, fp) != 1) goto fail; *raw_packet = (coap_bin_const_t *)scratch; + scratch = NULL; if (fread(&size, sizeof(size), 1, fp) != 1) goto fail; + /* If size == -1, then no oscore information */ if (size == -1) return 1; else if (size < 0 || size > 0x10000) @@ -348,7 +353,13 @@ coap_op_observe_read(FILE *fp, coap_subscription_t **observe_key, return 1; } fail: + coap_delete_bin_const(*raw_packet); coap_delete_binary(scratch); + + *observe_key = NULL; + memset(e_proto, 0, sizeof(*e_proto)); + memset(e_listen_addr, 0, sizeof(*e_listen_addr)); + memset(s_addr_info, 0, sizeof(*s_addr_info)); *raw_packet = NULL; return 0; } @@ -410,6 +421,7 @@ coap_op_observe_load_disk(coap_context_t *ctx) { if (fp_orig == NULL) goto fail; + new = coap_malloc_type(COAP_STRING, ctx->observe_save_file->length + 5); if (!new) goto fail; diff --git a/tests/test_options.c b/tests/test_options.c index 5746bec7..4397cec4 100644 --- a/tests/test_options.c +++ b/tests/test_options.c @@ -319,7 +319,7 @@ t_encode_option7(void) { CU_ASSERT(result == sizeof(teststr)); - CU_ASSERT(memcmp(buf, teststr, result) == 0); + CU_ASSERT(memcmp(buf, teststr, sizeof(teststr)) == 0); } static void