Check existance of cert info with given pkgid before compare it. 77/72177/6 accepted/tizen/common/20160608.160006 accepted/tizen/ivi/20160608.083949 accepted/tizen/mobile/20160608.083913 accepted/tizen/tv/20160608.083946 accepted/tizen/wearable/20160608.083923 submit/tizen/20160607.231554
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 31 May 2016 05:41:33 +0000 (14:41 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 8 Jun 2016 00:58:48 +0000 (17:58 -0700)
Codes are added to check existance of cert info for given 2 pkgids
before retrieve cert info and compare it.

Change-Id: Ibf56dad3997838e7dbcfde473344a1442b18624e
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/pkgmgrinfo_certinfo.c

index ae6e9c4..5508ffd 100644 (file)
@@ -62,17 +62,19 @@ static int _pkginfo_compare_certinfo(sqlite3 *db, const char *l_pkgid,
        int ret;
        sqlite3_stmt *stmt;
        const char *pkgid[2];
-       int certid[2] = {-1, };
+       int certid[2] = {-1, -1};
+       int exists[2] = {-1, -1};
        int i;
 
+       pkgid[0] = l_pkgid;
+       pkgid[1] = r_pkgid;
+
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
                _LOGE("prepare error: %s", sqlite3_errmsg(db));
                return PMINFO_R_ERROR;
        }
 
-       pkgid[0] = l_pkgid;
-       pkgid[1] = r_pkgid;
        for (i = 0; i < 2; i++) {
                ret = sqlite3_bind_text(stmt, 1, pkgid[i], -1, SQLITE_STATIC);
                if (ret != SQLITE_OK) {
@@ -83,28 +85,37 @@ static int _pkginfo_compare_certinfo(sqlite3 *db, const char *l_pkgid,
 
                ret = sqlite3_step(stmt);
                if (ret == SQLITE_ROW) {
+                       exists[i] = 1;
                        _save_column_int(stmt, 0, &certid[i]);
                } else if (ret != SQLITE_DONE) {
                        _LOGE("step error: %s", sqlite3_errmsg(db));
                        sqlite3_finalize(stmt);
                        return PMINFO_R_ERROR;
+               } else {
+                       exists[i] = 0;
                }
 
                sqlite3_reset(stmt);
                sqlite3_clear_bindings(stmt);
        }
 
-       if (certid[0] == -1 && certid[1] == -1)
+       if (exists[0] == 0 && exists[1] == 0) {
                *result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
-       else if (certid[0] == -1)
+               goto catch;
+       }       else if (exists[0] == 0) {
                *result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
-       else if (certid[1] == -1)
+               goto catch;
+       }       else if (exists[1] == 0) {
                *result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
-       else if (certid[0] == certid[1])
+               goto catch;
+       }
+
+       if (certid[0] == certid[1])
                *result = PMINFO_CERT_COMPARE_MATCH;
        else
                *result = PMINFO_CERT_COMPARE_MISMATCH;
 
+catch:
        sqlite3_finalize(stmt);
 
        return PMINFO_R_OK;