From a3c47b1412825746aee26ea72a8126ee13abc817 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Mon, 26 Mar 2018 12:48:35 +0900 Subject: [PATCH] Fix the issues that the results of APIs aren't handled This is for solving some coverity issues Change-Id: I46cc67240bff904c92886ed316be147028222c57 Signed-off-by: Sungbae Yoo --- rmi/app-proxy.h | 6 +++--- rmi/package-proxy.h | 6 +++--- server/manager.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++---------- server/packman.cpp | 16 +++++++++++++--- 4 files changed, 63 insertions(+), 19 deletions(-) diff --git a/rmi/app-proxy.h b/rmi/app-proxy.h index 2790f28..6e154f0 100644 --- a/rmi/app-proxy.h +++ b/rmi/app-proxy.h @@ -39,9 +39,9 @@ public: std::string type; std::string icon; std::string label; - int componentType; - bool isNoDisplayed; - bool isTaskManaged; + int componentType = 0; + bool isNoDisplayed = false; + bool isTaskManaged = false; REFLECTABLE (krate, id, locale, package, type, icon, label, diff --git a/rmi/package-proxy.h b/rmi/package-proxy.h index c4671ef..ccf56d1 100644 --- a/rmi/package-proxy.h +++ b/rmi/package-proxy.h @@ -48,9 +48,9 @@ public: std::string version; std::string apiVersion; std::string mainAppId; - bool isSystem; - bool isRemovable; - bool isPreload; + bool isSystem = false; + bool isRemovable = false; + bool isPreload = false; REFLECTABLE (krate, id, locale, type, icon, label, description, author, diff --git a/server/manager.cpp b/server/manager.cpp index ea3ac09..1fa9272 100755 --- a/server/manager.cpp +++ b/server/manager.cpp @@ -325,23 +325,33 @@ void notiProxyInsert(const runtime::User& owner, const runtime::User& user, int { std::string krateLauncherUri; notification_h newNoti; - app_control_h appControl; + app_control_h appControl = NULL; char* pkgId; + int ret; notification_clone(noti, &newNoti); notification_get_pkgname(noti, &pkgId); try { PackageInfo pkg(pkgId, user.getUid()); - notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON, pkg.getIcon().c_str()); + ret = notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON, pkg.getIcon().c_str()); + if (ret != NOTIFICATION_ERROR_NONE) { + throw runtime::Exception("notification_set_image"); + } } catch (runtime::Exception &e) { - notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON, DEFAULT_ICON_PATH); + ret = notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON, DEFAULT_ICON_PATH); + if (ret != NOTIFICATION_ERROR_NONE) { + ERROR(std::string("Failed to set an image to noti : ") + e.what()); + } } - notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, NOTIFICATION_SUB_ICON_PATH); + ret = notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, NOTIFICATION_SUB_ICON_PATH); + if (ret != NOTIFICATION_ERROR_NONE) { + ERROR("Failed to set a sub-image to noti"); + } - notification_get_launch_option(newNoti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, (void *)&appControl); - if (appControl != NULL) { + ret = notification_get_launch_option(newNoti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, (void *)&appControl); + if (ret == NOTIFICATION_ERROR_NONE && appControl != NULL) { char* appId = NULL, *uri = NULL; app_control_get_app_id(appControl, &appId); @@ -362,6 +372,7 @@ void notiProxyInsert(const runtime::User& owner, const runtime::User& user, int app_control_set_app_id(appControl, KRATE_DELEGATOR_APP); app_control_set_uri(appControl, krateLauncherUri.c_str()); notification_set_launch_option(newNoti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, appControl); + app_control_destroy(appControl); } notification_post_for_uid(newNoti, owner.getUid()); @@ -385,6 +396,7 @@ void notiProxyUpdate(const runtime::User& owner, const runtime::User& user, int std::unordered_map::iterator it; double progress; char *str; + int ret; it = notiHandleMap.find(privId); if (it == notiHandleMap.end()) { @@ -413,8 +425,13 @@ void notiProxyUpdate(const runtime::User& owner, const runtime::User& user, int }; for (notification_image_type_e type : imageTypes) { - notification_get_image(noti, type, &str); - notification_set_image(it->second, type, str); + ret = notification_get_image(noti, type, &str); + if (ret == NOTIFICATION_ERROR_NONE) { + ret = notification_set_image(it->second, type, str); + if (ret != NOTIFICATION_ERROR_NONE) { + ERROR("Failed to copy an image of noti"); + } + } } notification_text_type_e textTypes[] = { @@ -440,8 +457,13 @@ void notiProxyUpdate(const runtime::User& owner, const runtime::User& user, int }; for (notification_text_type_e type : textTypes) { - notification_get_text(noti, type, &str); - notification_set_text(it->second, type, str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + ret = notification_get_text(noti, type, &str); + if (ret == NOTIFICATION_ERROR_NONE) { + ret = notification_set_text(it->second, type, str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + if (ret != NOTIFICATION_ERROR_NONE) { + ERROR("Failed to copy a text of noti"); + } + } } notification_get_size(noti, &progress); @@ -541,6 +563,12 @@ int Manager::createKrate(const std::string& name, const std::string& manifest) for (int i = 0; i < GUMD_RETRY_COUNT && guser == NULL; i++) { guser = gum_user_create_sync(FALSE); } + + if (guser == NULL) { + ret = 1; + break; + } + g_object_set(G_OBJECT(guser), "username", name.c_str(), "usertype", GUM_USERTYPE_SECURITY, NULL); ret = gum_user_add_sync(guser); @@ -646,6 +674,12 @@ int Manager::removeKrate(const std::string& name) for (int i = 0; i < GUMD_RETRY_COUNT && guser == NULL; i++) { guser = gum_user_get_sync(user.getUid(), FALSE); } + + if (guser == NULL) { + ret = 1; + break; + } + ret = gum_user_delete_sync(guser, TRUE); g_object_unref(guser); } diff --git a/server/packman.cpp b/server/packman.cpp index 9425374..4e2cce7 100644 --- a/server/packman.cpp +++ b/server/packman.cpp @@ -37,7 +37,10 @@ int AppListCallback(pkgmgrinfo_appinfo_h handle, void *data) int PackageListCallback(pkgmgrinfo_pkginfo_h handle, void *data) { char* pkgid = nullptr; - ::pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); + + if (::pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK) { + return 0; + } std::vector* packageList = static_cast*>(data); packageList->push_back(pkgid); @@ -266,8 +269,15 @@ void ApplicationInfo::load(pkgmgrinfo_appinfo_h handle) { componentType = static_cast(comp); } - ::pkgmgrinfo_appinfo_is_nodisplay(handle, &noDisplayed); - ::pkgmgrinfo_appinfo_is_taskmanage(handle, &taskManaged); + ret = ::pkgmgrinfo_appinfo_is_nodisplay(handle, &noDisplayed); + if (ret != PMINFO_R_OK) { + noDisplayed = false; + } + + ret = ::pkgmgrinfo_appinfo_is_taskmanage(handle, &taskManaged); + if (ret != PMINFO_R_OK) { + taskManaged = false; + } } const std::string& ApplicationInfo::getId() const -- 2.7.4