Skip to content

Commit 49441ba

Browse files
committed
Fix issues reported by SonarCloud
1 parent d58c815 commit 49441ba

File tree

6 files changed

+36
-36
lines changed

6 files changed

+36
-36
lines changed

docker/apps/Dockerfile.cloud-server

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ WORKDIR /iotivity-lite
77
RUN git submodule update --recursive
88
RUN mkdir /iotivity-lite/build
99
WORKDIR /iotivity-lite/build
10-
RUN cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_TESTING=OFF -DOC_CLOUD_ENABLED=ON ${BUILD_ARGS} .. && \
10+
RUN cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_TESTING=OFF \
11+
-DOC_CLOUD_ENABLED=ON ${BUILD_ARGS} .. && \
1112
cmake --build . --target cloud_server
1213

1314
# install libfaketime

docker/apps/Dockerfile.cloud-server-debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ARG BUILD_TYPE=Release
33
ARG BUILD_ARGS
44
RUN apt-get update -y && \
55
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y bash \
6-
ca-certificates cmake curl gcovr gdb git-core g++ make patch python3 && \
6+
ca-certificates cmake curl g++ gcovr gdb git-core make patch python3 && \
77
apt-get clean
88
COPY ./ /iotivity-lite/
99
WORKDIR /iotivity-lite

port/android/ipadapter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,8 @@ recv_msg(int sock, uint8_t *recv_buf, int recv_buf_size,
732732
return -1;
733733
}
734734

735-
struct cmsghdr *cmsg;
736-
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != 0; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
735+
for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); cmsg != 0;
736+
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
737737
if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
738738
if (msg.msg_namelen != sizeof(struct sockaddr_in6)) {
739739
OC_ERR("anciliary data contains invalid source address");

port/esp32/adapter/src/ipadapter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,8 @@ recv_msg(int sock, uint8_t *recv_buf, int recv_buf_size,
553553
return -1;
554554
}
555555

556-
struct cmsghdr *cmsg;
557-
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != 0; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
556+
for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); cmsg != 0;
557+
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
558558
if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
559559
if (msg.msg_namelen != sizeof(struct sockaddr_in6)) {
560560
OC_ERR("anciliary data contains invalid source address");

port/linux/ip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ oc_ip_recv_msg(int sock, uint8_t *recv_buf, long recv_buf_size,
169169
return -1;
170170
}
171171

172-
struct cmsghdr *cmsg;
173-
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != 0; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
172+
for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); cmsg != 0;
173+
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
174174
if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO) {
175175
if (msg.msg_namelen != sizeof(struct sockaddr_in6)) {
176176
OC_ERR("anciliary data contains invalid source address");

security/oc_tls.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -744,29 +744,30 @@ check_retry_timers(void)
744744
{
745745
oc_tls_peer_t *peer = (oc_tls_peer_t *)oc_list_head(g_tls_peers);
746746
while (peer != NULL) {
747+
if (peer->ssl_ctx.state == MBEDTLS_SSL_HANDSHAKE_OVER ||
748+
!oc_etimer_expired(&peer->timer.fin_timer)) {
749+
peer = peer->next;
750+
continue;
751+
}
747752
oc_tls_peer_t *next = peer->next;
748-
if (peer->ssl_ctx.state != MBEDTLS_SSL_HANDSHAKE_OVER) {
749-
if (oc_etimer_expired(&peer->timer.fin_timer)) {
750-
int ret = mbedtls_ssl_handshake(&peer->ssl_ctx);
751-
if (ret == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) {
752-
mbedtls_ssl_session_reset(&peer->ssl_ctx);
753-
if (peer->role == MBEDTLS_SSL_IS_SERVER &&
754-
mbedtls_ssl_set_client_transport_id(
755-
&peer->ssl_ctx, (const unsigned char *)&peer->endpoint.addr,
756-
sizeof(peer->endpoint.addr)) != 0) {
757-
TLS_LOG_MBEDTLS_ERROR("mbedtls_ssl_set_client_transport_id", ret);
758-
oc_tls_free_peer(peer, false, false, true);
759-
peer = next;
760-
continue;
761-
}
762-
}
763-
if (ret < 0 && ret != MBEDTLS_ERR_SSL_WANT_READ &&
764-
ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
765-
TLS_LOG_MBEDTLS_ERROR("mbedtls_ssl_handshake", ret);
766-
oc_tls_free_peer(peer, false, false, true);
767-
}
753+
int ret = mbedtls_ssl_handshake(&peer->ssl_ctx);
754+
if (ret == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED) {
755+
mbedtls_ssl_session_reset(&peer->ssl_ctx);
756+
if (peer->role == MBEDTLS_SSL_IS_SERVER &&
757+
mbedtls_ssl_set_client_transport_id(
758+
&peer->ssl_ctx, (const unsigned char *)&peer->endpoint.addr,
759+
sizeof(peer->endpoint.addr)) != 0) {
760+
TLS_LOG_MBEDTLS_ERROR("mbedtls_ssl_set_client_transport_id", ret);
761+
oc_tls_free_peer(peer, false, false, true);
762+
peer = next;
763+
continue;
768764
}
769765
}
766+
if (ret < 0 && ret != MBEDTLS_ERR_SSL_WANT_READ &&
767+
ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
768+
TLS_LOG_MBEDTLS_ERROR("mbedtls_ssl_handshake", ret);
769+
oc_tls_free_peer(peer, false, false, true);
770+
}
770771
peer = next;
771772
}
772773
}
@@ -937,15 +938,13 @@ oc_tls_add_new_certs(oc_sec_credusage_t credusage,
937938
oc_sec_creds_t *creds = oc_sec_get_creds(device);
938939
oc_sec_cred_t *cred = (oc_sec_cred_t *)oc_list_head(creds->creds);
939940
for (; cred != NULL; cred = cred->next) {
940-
/* Pick all "leaf" certificates with matching credusage */
941-
if ((cred->credusage & credusage) != 0 && !cred->child) {
942-
943-
if (is_known_cert(cred)) {
944-
continue;
945-
}
946-
947-
add_new_cert(cred, device);
941+
/* Pick all "leaf" certificates with matching credusage that haven't been
942+
* added yet */
943+
if ((cred->credusage & credusage) == 0 || cred->child ||
944+
is_known_cert(cred)) {
945+
continue;
948946
}
947+
add_new_cert(cred, device);
949948
}
950949
}
951950
}

0 commit comments

Comments
 (0)