Fix Coverity issues of fido-client 91/174691/6
authorSandeep Sharma <sandeep.s9@samsung.com>
Fri, 6 Apr 2018 05:00:10 +0000 (10:30 +0530)
committersandeep sharma <sandeep.s9@samsung.com>
Tue, 10 Apr 2018 08:13:06 +0000 (08:13 +0000)
Patch #2 More fido-client fixes

Change-Id: Ic4590567358b95b827e39e724b79d27126301c1b
Signed-off-by: Susnata <s.sovalin@samsung.com>
common/fido_json_handler.c
server/fido_app_id_handler.c [changed mode: 0644->0755]
test/Dummy_ASM_DBUS/dummy_asm_server.c

index 98ade9f..d7cb399 100755 (executable)
@@ -479,9 +479,13 @@ __get_string_from_json_object(JsonObject *obj, const char *key)
                return NULL;
 
        const char *str = json_object_get_string_member(obj, key);
-       _INFO("[%s] = [%s]", key, str);
-
-       return strdup(str);
+       _INFO("[%s] ", key);
+       if (str != NULL) {
+               _INFO("[%s] ", str);
+               return strdup(str);
+       } else {
+               return NULL;
+       }
 }
 
 static int
@@ -1906,10 +1910,16 @@ _uaf_composer_compose_final_challenge(const char *app_id, const char *challenge,
                        return NULL;
 
                JsonNode *chb_root = json_parser_get_root(chb_parser);
-               RET_IF_FAIL(chb_root != NULL, NULL);
+               if (chb_root == NULL) {
+                       g_object_unref(builder);
+                       return NULL;
+               }
 
                JsonObject *chb_root_obj = json_node_get_object(chb_root);
-               RET_IF_FAIL(chb_root_obj != NULL, NULL);
+               if (chb_root_obj == NULL) {
+                       g_object_unref(builder);
+                       return NULL;
+               }
 
                char *end_pt = __get_string_from_json_object(chb_root_obj, _JSON_KEY_SERVER_END_POINT);
                char *cert = __get_string_from_json_object(chb_root_obj, _JSON_KEY_TLS_SERVER_CERT);
@@ -2489,28 +2499,19 @@ _uaf_composer_compose_dereg_request(_response_t *uaf_res)
                        }
                        SAFE_DELETE(key_id_enc);
                }
-
                _INFO("after assertions");
 
                _free_auth_reg_assertion_tlv(assrt_tlv);
 
                json_builder_end_object(obj);
-
-
                assertions_iter = assertions_iter->next;
-
+               SAFE_DELETE(aaid);
        }
-
        json_builder_end_array(auth_root);
        /*authenticators*/
-
-
        json_builder_end_object(uaf_1_root);
-
-
        json_builder_end_array(root_array);
 
-
        JsonNode *root_builder = json_builder_get_root(builder);
        JsonGenerator *gen = json_generator_new();
        json_generator_set_root(gen, root_builder);
old mode 100644 (file)
new mode 100755 (executable)
index d6684e0..c9cf93a
@@ -209,10 +209,16 @@ __get_pub_key(const char *json_id_str)
        RET_IF_FAIL(json_id_str != NULL, NULL);
 
 
-       char *save_ptr;
-       char *os = strtok_r(strdup(json_id_str), ":", &save_ptr);
+       char *save_ptr = NULL, *tempStr = NULL;
+       tempStr = strdup(json_id_str);
+       RET_IF_FAIL(json_id_str != NULL, NULL);
+
+       char *os = strtok_r(tempStr, ":", &save_ptr);
 
-       RET_IF_FAIL(os != NULL, NULL);
+       if (os == NULL) {
+               free(tempStr);
+               return NULL;
+       }
 
        if (strcmp(os, FIDO_APP_ID_KEY_TIZEN) != 0) {
                _ERR("[%s] is not supported", os);
@@ -220,7 +226,10 @@ __get_pub_key(const char *json_id_str)
        }
 
        char *type = strtok_r(NULL, ":", &save_ptr);
-       RET_IF_FAIL(type != NULL, NULL);
+
+       if (type == NULL) {
+               return NULL;
+       }
 
        if (strcmp(type, FIDO_APP_ID_KEY_PKG_HASH) != 0) {
                _ERR("[%s] is not supported", type);
@@ -568,7 +577,7 @@ __get_tz_facet_id_of_caller(const char *caller_app_id, GDBusMethodInvocation *in
        tz_facet_id = (char*)(calloc(1, tz_facet_id_max_len));
        snprintf(tz_facet_id, tz_facet_id_max_len, "%s:%s", "tizen:pkg-key-hash",
                         author_cert_hash);
-
+       SAFE_DELETE(author_cert_hash);
 CATCH:
        pkgmgrinfo_pkginfo_destroy_certinfo(cert_handle);
        pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
index ad87871..0b24aef 100755 (executable)
@@ -159,9 +159,11 @@ __get_request_type(const char *asm_req_json)
        JsonObject *root_obj = json_node_get_object(root);
 
        const char *req_type = json_object_get_string_member(root_obj, "requestType");
-
-       return strdup(req_type);
-
+       if (req_type != NULL) {
+               return strdup(req_type);
+       } else {
+               return NULL;
+       }
 }
 
 gboolean
@@ -201,6 +203,7 @@ _dbus_on_asm_request(Dummyasm *object, GDBusMethodInvocation *invocation, const
        if (strcmp(req_type, "GetRegistrations") == 0)
                dummyasm_complete_asm_request(object, invocation, 0, _GET_REGISTRATIONS_RESPONSE);
 
+       free(req_type);
        return true;
 }