diff --git a/api/oc_server_api.c b/api/oc_server_api.c index 17da1465e5..d6458762b8 100644 --- a/api/oc_server_api.c +++ b/api/oc_server_api.c @@ -506,7 +506,9 @@ oc_add_collection_v1(oc_resource_t *collection) void oc_add_collection(oc_resource_t *collection) { - oc_add_collection_v1(collection); + if (!oc_add_collection_v1(collection)) { + OC_ERR("failed to add collection"); + } } oc_resource_t * diff --git a/apps/client_certification_tests.c b/apps/client_certification_tests.c index 8063b1d4ee..14e910c9de 100644 --- a/apps/client_certification_tests.c +++ b/apps/client_certification_tests.c @@ -603,7 +603,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/apps/cloud_certification_tests.c b/apps/cloud_certification_tests.c index d2a809727b..cfad6ee187 100644 --- a/apps/cloud_certification_tests.c +++ b/apps/cloud_certification_tests.c @@ -544,7 +544,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (pem_len > (long)*buffer_len) { + if (pem_len >= (long)*buffer_len) { OC_PRINTF("ERROR: buffer provided too small\n"); fclose(fp); return -1; @@ -554,7 +554,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/apps/cloud_client.c b/apps/cloud_client.c index 8935b7ebc0..423d9ddb82 100644 --- a/apps/cloud_client.c +++ b/apps/cloud_client.c @@ -315,7 +315,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (pem_len > (long)*buffer_len) { + if (pem_len >= (long)*buffer_len) { OC_PRINTF("ERROR: buffer provided too small\n"); fclose(fp); return -1; @@ -325,7 +325,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/apps/cloud_proxy.c b/apps/cloud_proxy.c index 3666a5bc77..156d57aea0 100644 --- a/apps/cloud_proxy.c +++ b/apps/cloud_proxy.c @@ -1634,7 +1634,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (pem_len > (long)*buffer_len) { + if (pem_len >= (long)*buffer_len) { OC_PRINTF("ERROR: buffer provided too small\n"); fclose(fp); return -1; @@ -1644,7 +1644,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/apps/cloud_server.c b/apps/cloud_server.c index 84dbb29171..346e21d362 100644 --- a/apps/cloud_server.c +++ b/apps/cloud_server.c @@ -828,7 +828,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (pem_len > (long)*buffer_len) { + if (pem_len >= (long)*buffer_len) { OC_PRINTF("ERROR: buffer provided too small\n"); fclose(fp); return -1; @@ -838,7 +838,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/apps/server_certification_tests.c b/apps/server_certification_tests.c index 84472be2d9..d44d1b4fc5 100644 --- a/apps/server_certification_tests.c +++ b/apps/server_certification_tests.c @@ -2023,7 +2023,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/apps/smart_home_server_linux.c b/apps/smart_home_server_linux.c index e025792425..17a045e706 100644 --- a/apps/smart_home_server_linux.c +++ b/apps/smart_home_server_linux.c @@ -737,7 +737,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { printf("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/apps/smart_home_server_with_mock_swupdate.cpp b/apps/smart_home_server_with_mock_swupdate.cpp index c66a7bb69c..f0b61bd502 100644 --- a/apps/smart_home_server_with_mock_swupdate.cpp +++ b/apps/smart_home_server_with_mock_swupdate.cpp @@ -272,7 +272,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/onboarding_tool/obtmain.c b/onboarding_tool/obtmain.c index 48a401fa1b..b2e308c6b2 100644 --- a/onboarding_tool/obtmain.c +++ b/onboarding_tool/obtmain.c @@ -1760,7 +1760,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (pem_len > (long)*buffer_len) { + if (pem_len >= (long)*buffer_len) { OC_PRINTF("ERROR: buffer provided too small\n"); fclose(fp); return -1; @@ -1770,7 +1770,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("ERROR: unable to read PEM\n"); fclose(fp); return -1; diff --git a/python/oc_python.c b/python/oc_python.c index eeb0810511..4477e56708 100644 --- a/python/oc_python.c +++ b/python/oc_python.c @@ -1492,7 +1492,7 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (pem_len > (long)*buffer_len) { + if (pem_len >= (long)*buffer_len) { OC_PRINTF("[C]ERROR: buffer provided too small\n"); fclose(fp); return -1; @@ -1502,7 +1502,8 @@ read_pem(const char *file_path, char *buffer, size_t *buffer_len) fclose(fp); return -1; } - if (fread(buffer, 1, pem_len, fp) < (size_t)pem_len) { + size_t to_read = (size_t)pem_len; + if (fread(buffer, 1, to_read, fp) < (size_t)pem_len) { OC_PRINTF("[C]ERROR: unable to read PEM\n"); fclose(fp); return -1;