From 0eaf8040ae696e6b227f2437a89d595b42ed4823 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Tue, 1 Dec 2020 10:49:39 +0900 Subject: [PATCH] Fix static analysis issues Change-Id: I4865c112274c9aec03770aebe59cff8ec2b180c0 Signed-off-by: Junghyun Yeon --- src/pkg_upgrade/src/main.cc | 12 +++++++++--- src/pkg_upgrade/src/upgrader.cc | 23 +++++++++++++++++++---- src/pkgcmd/pkg_cmd.c | 12 ++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/pkg_upgrade/src/main.cc b/src/pkg_upgrade/src/main.cc index 9d2eea2..dc3e8d4 100644 --- a/src/pkg_upgrade/src/main.cc +++ b/src/pkg_upgrade/src/main.cc @@ -14,15 +14,21 @@ * limitations under the License. */ +#include "logging.hh" #include "pkg_finder.hh" #include "upgrader.hh" int main(int argc, char *argv[]) { - common_fota::PkgFinder finder; - common_fota::Upgrader upgrader; + try { + common_fota::PkgFinder finder; + common_fota::Upgrader upgrader; - if (!upgrader.Process(&finder)) + if (!upgrader.Process(&finder)) + return -1; + } catch (...) { + LOG(ERROR) << "Exception occured"; return -1; + } return 0; } diff --git a/src/pkg_upgrade/src/upgrader.cc b/src/pkg_upgrade/src/upgrader.cc index ea7f5b5..100e85f 100644 --- a/src/pkg_upgrade/src/upgrader.cc +++ b/src/pkg_upgrade/src/upgrader.cc @@ -365,10 +365,25 @@ int Upgrader::MakeBackupDbs() { return 0; CATCH: - remove(parser_db_bck.c_str()); - remove(parser_db_journal_bck.c_str()); - remove(cert_db_bck.c_str()); - remove(cert_db_journal_bck.c_str()); + if (remove(parser_db_bck.c_str())) { + LOG(WARNING) << "cannot remove backup file(" + << parser_db_bck << ") " << errno; + } + + if (remove(parser_db_journal_bck.c_str())) { + LOG(WARNING) << "cannot remove backup file(" + << parser_db_journal_bck << ") " << errno; + } + + if (remove(cert_db_bck.c_str())) { + LOG(WARNING) << "cannot remove backup file(" + << cert_db_bck << ") " << errno; + } + + if (remove(cert_db_journal_bck.c_str())) { + LOG(WARNING) << "cannot remove backup file(" + << cert_db_journal_bck << ") " << errno; + } return -1; } diff --git a/src/pkgcmd/pkg_cmd.c b/src/pkgcmd/pkg_cmd.c index 75e1ef4..0a9ee9b 100644 --- a/src/pkgcmd/pkg_cmd.c +++ b/src/pkgcmd/pkg_cmd.c @@ -626,6 +626,10 @@ static int __install_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data, n_pkgs = g_list_length(data->pkgs); pkgs = malloc(sizeof(char *) * n_pkgs); + if (pkgs == NULL) { + printf("Out of memory\n"); + return -1; + } for (l = data->pkgs, i = 0; l; l = l->next, i++) pkgs[i] = (char *)l->data; @@ -708,6 +712,10 @@ static int __uninstall_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data, n_pkgs = g_list_length(data->pkgs); pkgs = malloc(sizeof(char *) * n_pkgs); + if (pkgs == NULL) { + printf("Out of memory\n"); + return -1; + } for (l = data->pkgs, i = 0; l; l = l->next, i++) pkgs[i] = (char *)l->data; @@ -828,6 +836,10 @@ static int __mount_install_multiple_pkgs(pkgmgr_client *pc, pm_tool_args *data, n_pkgs = g_list_length(data->pkgs); pkgs = malloc(sizeof(char *) * n_pkgs); + if (pkgs == NULL) { + printf("Out of memory\n"); + return -1; + } for (l = data->pkgs, i = 0; l; l = l->next, i++) pkgs[i] = (char *)l->data; -- 2.34.1