Add codes and comments for possible static analysis issues 29/256729/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 12 Apr 2021 05:03:12 +0000 (14:03 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 21 Apr 2021 05:33:05 +0000 (05:33 +0000)
- Add copyright comments.
- Add parameter check logic.

Change-Id: I8526900ae44c3423914f49b90d0eb2afe89d27ef
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/appinfo_internal.c
src/certinfo_internal.c
src/pkginfo_internal.c

index 2de2546..006fd78 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
index db5a239..4ccdd95 100644 (file)
@@ -1,4 +1,18 @@
-// copyright
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 #define _GNU_SOURCE
 #include <stdio.h>
@@ -146,7 +160,7 @@ API int certinfo_internal_get(sqlite3 *db, const char *pkgid, uid_t uid,
        int ret;
        pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)certinfo;
 
-       if (pkgid == NULL || certinfo == NULL)
+       if (db == NULL || pkgid == NULL || certinfo == NULL)
                return PMINFO_R_EINVAL;
        ret = _pkginfo_get_certinfo(db, pkgid, info);
        if (ret != PMINFO_R_OK)
@@ -314,7 +328,7 @@ API int certinfo_internal_set(sqlite3 *db, const char *pkgid,
        int ret;
        pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)handle;
 
-       if (pkgid == NULL || handle == NULL) {
+       if (db == NULL || pkgid == NULL || handle == NULL) {
                _LOGE("invalid parameter");
                return PMINFO_R_EINVAL;
        }
@@ -363,6 +377,9 @@ API int certinfo_internal_delete(sqlite3 *db, const char *pkgid)
        int ret;
        sqlite3_stmt *stmt;
 
+       if (db == NULL || pkgid == NULL)
+               return PMINFO_R_EINVAL;
+
        query = sqlite3_mprintf("UPDATE package_cert_info "
                        "SET package_count = package_count - 1 "
                        "WHERE package=%Q", pkgid);
index 8dacecc..035477e 100644 (file)
@@ -1,4 +1,18 @@
-// copyright
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 #define _GNU_SOURCE
 #include <stdio.h>
@@ -413,30 +427,21 @@ static int _pkginfo_get_packages(sqlite3 *db, uid_t uid, const char *locale,
        static const char query_from_clause[] = " FROM package_info as pi";
        int ret = PMINFO_R_ERROR;
        int idx = 0;
-       //char *dbpath;
        char *tmp_record = NULL;
        char *constraints = NULL;
        char query[MAX_QUERY_LEN] = { '\0' };
        package_x *info = NULL;
        author_x *author = NULL;
        GList *bind_params = NULL;
-       //sqlite3 *db;
        sqlite3_stmt *stmt = NULL;
        bool is_check_storage = true;
        const uid_t global_user_uid = GLOBAL_USER;
-#if 0
-       dbpath = getUserPkgParserDBPathUID(uid);
-       if (dbpath == NULL)
-               return PMINFO_R_ERROR;
 
-       ret = __open_db(dbpath, &db, SQLITE_OPEN_READONLY);
-       if (ret != SQLITE_OK) {
-               _LOGD("failed to open db(%s): %d", dbpath, ret);
-               free(dbpath);
-               return PMINFO_R_ERROR;
+       if (db == NULL || locale == NULL || filter == NULL) {
+               LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
        }
-       free(dbpath);
-#endif
+
        is_check_storage = __check_package_storage_status(filter);
 
        snprintf(query, MAX_QUERY_LEN - 1, "%s", query_raw);
@@ -659,6 +664,11 @@ API int get_query_result(sqlite3 *db, const char *query, GList *param,
        sqlite3_stmt *stmt = NULL;
        char *result = NULL;
 
+       if (db == NULL || query == NULL) {
+               LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
                LOGE("prepare failed: %s", sqlite3_errmsg(db));
@@ -759,6 +769,11 @@ API int pkginfo_internal_filter_get_depends_on(sqlite3 *db, const char *pkgid,
        char *item;
        int ret;
 
+       if (db == NULL || pkgid == NULL) {
+               LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
        queue = g_queue_new();
        if (queue == NULL) {
                LOGE("out of memory");
@@ -821,6 +836,12 @@ API int execute_write_queries(sqlite3 *db, GList *queries, GList *params_list)
        int i;
        int j;
        query_args *tmp_ptr = NULL;
+
+       if (db == NULL || queries == NULL) {
+               _LOGE("Invalid parameter");
+               return PMINFO_R_EINVAL;
+       }
+
        __BEGIN_TRANSACTION(db);
        for (i = 0; i < g_list_length(queries); ++i) {
                tmp_ptr = (query_args *)g_list_nth_data(params_list, i);