Coverity: Fix CID 1469636, 1514378, 1520611 and 1566432

This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2023-08-19 14:07:21 +01:00
1 parent 760dd4bc9b
commit d295ccb638
4 files changed
+17 -5

No files matched your search

+1 -1
View File
@@ -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);
+2 -2
View File
@@ -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);
+13 -1
View File
@@ -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;
+1 -1
View File
@@ -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