Skip to content

Commit

Permalink
fixup! Fix issues reported by Coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Sep 26, 2024
1 parent ba2842d commit 0c5efeb
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ jobs:
- args: "-DOC_IPV4_ENABLED=ON -DOC_TCP_ENABLED=ON -DOC_PKI_ENABLED=OFF"
# cloud on (ipv4+tcp on), dynamic allocation off, push notifications off
- args: "-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_PUSH_ENABLED=OFF"
# cloud on (ipv4+tcp on), collections create on
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON"
# cloud on (ipv4+tcp on), collections create on, dps on, dps test properties on
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_TEST_PROPERTIES_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_MAXIMUM_LOG_LEVEL=INFO"
# cloud on (ipv4+tcp on), collections create on, custom message buffer size, custom message buffer pool size, custom app data buffer size, custom app data buffer pool size
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_INOUT_BUFFER_SIZE=2048 -DOC_INOUT_BUFFER_POOL=4 -DOC_APP_DATA_BUFFER_SIZE=2048 -DOC_APP_DATA_BUFFER_POOL=4"
# debug on
Expand Down
5 changes: 2 additions & 3 deletions api/plgd/device-provisioning-client/plgd_dps_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@

static struct
{
plgd_dps_print_log_fn_t fn; ///< logging function
OC_ATOMIC_INT8_T level; ///< enabled log level
OC_ATOMIC_UINT32_T components; ///< mask of enabled log components
plgd_dps_print_log_fn_t fn; ///< logging function
OC_ATOMIC_INT8_T level; ///< enabled log level
} g_dps_logger = {
.fn = NULL,
.level = OC_LOG_LEVEL_INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ dps_handle_set_cloud_response(oc_client_response_t *data)
}
oc_string_view_t sidv = oc_string_view2(cloud.sid);
oc_uuid_t sid;
oc_str_to_uuid_v1(sidv.data, sidv.length, &sid);
if (oc_str_to_uuid_v1(sidv.data, sidv.length, &sid) < 0) {
DPS_ERR("invalid sid(%s) value", sidv.data);
return PLGD_DPS_ERROR_SET_CLOUD;
}
const oc_string_t *cloud_apn =
oc_cloud_get_authorization_provider_name(cloud_ctx);
if (dps_is_equal_string(*cloud_ctx_cis, *cloud.ci_server) &&
Expand Down
19 changes: 0 additions & 19 deletions api/plgd/unittest/plgd_dps_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,4 @@ TEST_F(TestDPSLog, LogToFunction)
DPS_LOG(OC_LOG_LEVEL_TRACE, "trace");
}

static void
expectNoLog(oc_log_level_t, const char *, int, const char *, const char *, ...)
{
FAIL() << "unexpected log";
}

TEST_F(TestDPSLog, SkipLogByComponent)
{
plgd_dps_log_set_level(OC_LOG_LEVEL_TRACE);
plgd_dps_set_log_fn(expectNoLog);

DPS_ERR("error");
DPS_WRN("warning");
DPS_NOTE("notice");
DPS_INFO("info");
DPS_DBG("debug");
DPS_TRACE("trace");
}

#endif /* OC_HAS_FEATURE_PLGD_DEVICE_PROVISIONING */
29 changes: 21 additions & 8 deletions apps/dps_cloud_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,21 @@ register_collection(size_t device)
oc_resource_set_discoverable(col, true);
oc_resource_set_observable(col, true);

oc_collection_add_supported_rt(col, "oic.r.switch.binary");
oc_collection_add_mandatory_rt(col, "oic.r.switch.binary");
if (!oc_collection_add_supported_rt(col, "oic.r.switch.binary")) {
printf("ERROR: could not add supported resource type to collection\n");
return false;
}
if (!oc_collection_add_mandatory_rt(col, "oic.r.switch.binary")) {
printf("ERROR: could not add mandatory resource type to collection\n");
return false;
}
#ifdef OC_COLLECTIONS_IF_CREATE
oc_resource_bind_resource_interface(col, OC_IF_CREATE);
oc_collections_add_rt_factory("oic.r.switch.binary", get_switch_instance,
free_switch_instance);
if (!oc_collections_add_rt_factory("oic.r.switch.binary", get_switch_instance,
free_switch_instance)) {
OC_PRINTF("ERROR: could not register rt factory\n");
return false;
}
#endif /* OC_COLLECTIONS_IF_CREATE */
/* The following enables baseline RETRIEVEs/UPDATEs to Collection properties
*/
Expand Down Expand Up @@ -1508,15 +1517,19 @@ dps_dhcp_parse_vendor_encapsulated_options(const char *value, size_t size,
ssize_t len = plgd_dps_hex_string_to_bytes(value, size, NULL, 0);
if (len < 0) {
printf("ERROR: invalid character in vendor encapsulated options\n");
return true;
return false;
}
if (len > (ssize_t)(sizeof(veo->value))) {
if ((size_t)len > sizeof(veo->value)) {
printf("ERROR: vendor encapsulated options too long\n");
return true;
return false;
}
len =
plgd_dps_hex_string_to_bytes(value, size, veo->value, sizeof(veo->value));
if (len < (ssize_t)(sizeof(veo->value))) {
if (len < 0) {
printf("ERROR: invalid hex string\n");
return false;
}
if ((size_t)len < sizeof(veo->value)) {
veo->value[len] = '\0';
}
veo->size = (size_t)len;
Expand Down
2 changes: 1 addition & 1 deletion port/linux/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ oc_ip_send_msg(int sock, struct sockaddr_storage *receiver,
}
// overflow check for coverity scan
assert(bytes_sent <= SIZE_MAX - (size_t)ret && "Integer overflow detected");
bytes_sent += ret;
bytes_sent += (size_t)ret;
}
OC_TRACE("Sent %zu bytes", bytes_sent);
if (bytes_sent == 0) {
Expand Down
2 changes: 1 addition & 1 deletion port/linux/tcpsession.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ tcp_send_message(int sockfd, const oc_message_t *message)
// overflow check for coverity scan
assert(bytes_sent <= SIZE_MAX - (size_t)send_len &&
"Integer overflow detected");
bytes_sent += send_len;
bytes_sent += (size_t)send_len;
} while (bytes_sent < message->length);

OC_TRACE("Sent %zu bytes", bytes_sent);
Expand Down
10 changes: 2 additions & 8 deletions util/jsmn/jsmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ jsmn_parse_next_char(jsmn_parser_t *parser, jsmntok_t *token, const char *js,
return r;
}
// overflow check for coverity scan
// assert(count <= INT_MAX - r && "Integer overflow detected");
if (count > INT_MAX - r) {
return -1;
}
assert(count <= INT_MAX - r && "Integer overflow detected");
count += r;
break;
}
Expand Down Expand Up @@ -302,10 +299,7 @@ jsmn_parse(jsmn_parser_t *parser, const char *js, const size_t len,
return r;
}
// overflow check for coverity scan
// assert(count <= INT_MAX - r && "Integer overflow detected");
if (count > INT_MAX - r) {
return -1;
}
assert(count <= INT_MAX - r && "Integer overflow detected");
count += r;
}

Expand Down

0 comments on commit 0c5efeb

Please sign in to comment.