Skip to content

Commit

Permalink
api/cloud: fix coverity issues
Browse files Browse the repository at this point in the history
319236, 319242: Unchecked return value
  • Loading branch information
Danielius1922 committed Jun 27, 2023
1 parent 6bda020 commit 28a03e3
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 94 deletions.
33 changes: 20 additions & 13 deletions api/cloud/oc_cloud_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,34 @@ cloud_update_from_request(oc_cloud_context_t *ctx, const oc_request_t *request)
cloud_conf_update_t data;
memset(&data, 0, sizeof(data));

char *access_token;
char *access_token = NULL;
bool has_at =
oc_rep_get_string(request->request_payload, OC_RSRVD_ACCESSTOKEN,
&access_token, &data.access_token_len);
data.access_token = access_token;
if (has_at) {
data.access_token = access_token;
}

char *auth_provider;
oc_rep_get_string(request->request_payload, OC_RSRVD_AUTHPROVIDER,
&auth_provider, &data.auth_provider_len);
data.auth_provider = auth_provider;
char *auth_provider = NULL;
if (oc_rep_get_string(request->request_payload, OC_RSRVD_AUTHPROVIDER,
&auth_provider, &data.auth_provider_len)) {
data.auth_provider = auth_provider;
}

char *ci_server;
char *ci_server = NULL;
bool has_cis = oc_rep_get_string(request->request_payload, OC_RSRVD_CISERVER,
&ci_server, &data.ci_server_len);
data.ci_server = ci_server;
if (has_cis) {
data.ci_server = ci_server;
}

// OCF 2.0 spec version added sid property.
char *sid;
char *sid = NULL;
bool has_sid = oc_rep_get_string(request->request_payload, OC_RSRVD_SERVERID,
&sid, &data.sid_len);
data.sid = sid;
if (has_sid) {
data.sid = sid;
}

if (has_cis && (data.ci_server_len == 0 || (has_at && has_sid))) {
cloud_update_by_resource(ctx, &data);
Expand Down Expand Up @@ -173,9 +180,9 @@ post_cloud(oc_request_t *request, oc_interface_mask_t interface,
//
char *cis;
size_t cis_len = 0;
oc_rep_get_string(request->request_payload, OC_RSRVD_CISERVER, &cis,
&cis_len);
if (cis_len == 0) {
if (oc_rep_get_string(request->request_payload, OC_RSRVD_CISERVER, &cis,
&cis_len) &&
cis_len == 0) {
request_invalid_in_state = false;
}
}
Expand Down
163 changes: 82 additions & 81 deletions python/oc_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -1888,95 +1888,96 @@ resource_discovery(const char *anchor, const char *uri, oc_string_array_t types,
(void)bm;
(void)types;
(void)endpoint;
char strtypes[200] = " ";
char strinterfaces[200] = " ";

if (uri == NULL) {
OC_PRINTF("[C]\nERROR DISCOVERING RESOURCES\n");
cb_result = false;
return OC_STOP_DISCOVERY;
}

char json[1024] = "";
strcat(json, "{\"uri\" : \"");
strcat(json, uri);
strcat(json, "\",");

if (uri) {
strcat(json, "{\"uri\" : \"");
strcat(json, uri);
strcat(json, "\",");

strcat(json, "\"types\": [");
int array_size = (int)oc_string_array_get_allocated_size(types);
for (int i = 0; i < array_size; i++) {
const char *t = oc_string_array_get_item(types, i);
strcat(strtypes, "\"");
strcat(strtypes, t);
strcat(strtypes, "\"");
if (i < array_size - 1) {
strcat(strtypes, ",");
}
char strtypes[200] = " ";
strcat(json, "\"types\": [");
int array_size = (int)oc_string_array_get_allocated_size(types);
for (int i = 0; i < array_size; i++) {
const char *t = oc_string_array_get_item(types, i);
strcat(strtypes, "\"");
strcat(strtypes, t);
strcat(strtypes, "\"");
if (i < array_size - 1) {
strcat(strtypes, ",");
}
strcat(json, strtypes);
strcat(json, "],");
}
strcat(json, strtypes);
strcat(json, "],");

strcat(json, "\"if\": [");
bool comma = false;
strcat(json, "\"if\": [");
bool comma = false;

// OC_PRINTF (" %d", if)
if ((iface_mask & OC_IF_BASELINE) == OC_IF_BASELINE) {
strcat(strinterfaces, "\"oic.r.baseline\"");
comma = true;
}
if ((iface_mask & OC_IF_RW) == OC_IF_RW) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.rw\"");
comma = true;
}
if ((iface_mask & OC_IF_R) == OC_IF_R) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.r\"");
comma = true;
}
if ((iface_mask & OC_IF_S) == OC_IF_S) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.s\"");
comma = true;
}
if ((iface_mask & OC_IF_A) == OC_IF_A) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.a\"");
comma = true;
}
if ((iface_mask & OC_IF_CREATE) == OC_IF_CREATE) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.create\"");
comma = true;
}
if ((iface_mask & OC_IF_LL) == OC_IF_LL) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.ll\"");
comma = true;
}
if ((iface_mask & OC_IF_B) == OC_IF_B) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.b\"");
}
strcat(json, strinterfaces);
strcat(json, "]");
strcat(json, "}");

// OC_PRINTF("[C]anchor %s, uri : %s\n", anchor, uri);
inform_resource_python(anchor, uri, strtypes, json);
if (!more) {
OC_PRINTF("[C]----End of discovery response---\n");
cb_result = true;
return OC_STOP_DISCOVERY;
char strinterfaces[200] = " ";
// OC_PRINTF (" %d", if)
if ((iface_mask & OC_IF_BASELINE) == OC_IF_BASELINE) {
strcat(strinterfaces, "\"oic.r.baseline\"");
comma = true;
}
if ((iface_mask & OC_IF_RW) == OC_IF_RW) {
if (comma) {
strcat(strinterfaces, ",");
}
return OC_CONTINUE_DISCOVERY;
} else {
OC_PRINTF("[C]\nERROR DISCOVERING RESOURCES\n");
cb_result = false;
strcat(strinterfaces, "\"oic.r.rw\"");
comma = true;
}
if ((iface_mask & OC_IF_R) == OC_IF_R) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.r\"");
comma = true;
}
if ((iface_mask & OC_IF_S) == OC_IF_S) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.s\"");
comma = true;
}
if ((iface_mask & OC_IF_A) == OC_IF_A) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.a\"");
comma = true;
}
if ((iface_mask & OC_IF_CREATE) == OC_IF_CREATE) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.create\"");
comma = true;
}
if ((iface_mask & OC_IF_LL) == OC_IF_LL) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.ll\"");
comma = true;
}
if ((iface_mask & OC_IF_B) == OC_IF_B) {
if (comma)
strcat(strinterfaces, ",");
strcat(strinterfaces, "\"oic.r.b\"");
}
strcat(json, strinterfaces);
strcat(json, "]");
strcat(json, "}");

// OC_PRINTF("[C]anchor %s, uri : %s\n", anchor, uri);
inform_resource_python(anchor, uri, strtypes, json);
if (!more) {
OC_PRINTF("[C]----End of discovery response---\n");
cb_result = true;
return OC_STOP_DISCOVERY;
}
return OC_CONTINUE_DISCOVERY;
}

void
Expand Down

0 comments on commit 28a03e3

Please sign in to comment.