suppress build warnings 93/61993/1 accepted/tizen/common/20160317.155403 accepted/tizen/ivi/20160315.001445 accepted/tizen/mobile/20160315.001358 accepted/tizen/tv/20160315.001408 accepted/tizen/wearable/20160315.001423 submit/tizen/20160314.031145 submit/tizen_common/20160316.154911
authorJunghyun Yeon <jungh.yeon@samsung.com>
Sat, 12 Mar 2016 05:26:42 +0000 (14:26 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Sat, 12 Mar 2016 05:26:42 +0000 (14:26 +0900)
Change-Id: Iea0c6ccb96fbd96d9d3dfffd7a0757b34d3a116e
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/install_preload_tpk.c
src/pkg_cmd.c
src/pkg_initdb.c

index 5bdbdce..e9d7e7b 100644 (file)
@@ -23,6 +23,8 @@
 #include <dirent.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <errno.h>
 
 #include <tzplatform_config.h>
@@ -70,7 +72,11 @@ static int _install_preload_tpk(uid_t uid, const char *directory)
 
                pid_t pid = fork();
                if (pid == 0) {
-                       setuid(uid);
+                       if (setuid(uid) != 0) {
+                               _E("failed to set uid");
+                               closedir(dir);
+                               return -1;
+                       }
                        execl(BACKEND_CMD, BACKEND_CMD, "-i", buf, "--preload",
                              (char*)NULL);
                } else if (pid < 0) {
@@ -100,7 +106,6 @@ static int _is_authorized(uid_t uid)
 
 int main(int argc, char *argv[])
 {
-       int ret;
        const char *dir = tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk");
        uid_t uid = getuid();
 
index 6c6d019..1540353 100644 (file)
@@ -339,8 +339,7 @@ static int __convert_to_absolute_tep_path(char *path)
        }
        strncpy(temp, path, PATH_MAX - 1);
        if (strchr(path, '/') == NULL) {
-               getcwd(abs, PATH_MAX - 1);
-               if (abs[0] == '\0') {
+               if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') {
                        printf("getcwd() failed\n");
                        return -1;
                }
@@ -350,8 +349,7 @@ static int __convert_to_absolute_tep_path(char *path)
        }
        if (strncmp(path, "./", 2) == 0) {
                ptr = temp;
-               getcwd(abs, PATH_MAX - 1);
-               if (abs[0] == '\0') {
+               if (getcwd(abs, PATH_MAX - 1) == NULL || abs[0] == '\0') {
                        printf("getcwd() failed\n");
                        return -1;
                }
@@ -381,48 +379,6 @@ static int __is_app_installed(char *pkgid, uid_t uid)
        return 0;
 }
 
-static char *__get_pkgid_from_tep(const char *filename)
-{
-       char *pkg_type = NULL;
-       char pkg_file[PATH_MAX] = { '\0', };
-       char *tmp = NULL;
-       char *pkgid = NULL;
-       size_t pkgid_len = 0;
-
-       if (strrchr(filename, '/')) {
-               strncpy(pkg_file, strrchr(filename, '/') + 1, PATH_MAX - 1);
-       } else {
-               strncpy(pkg_file, filename, PATH_MAX - 1);
-       }
-
-       pkg_type = strrchr(pkg_file, '.');
-       if (pkg_type == NULL) {
-               printf("pkg_type is null[%s]\n", filename);
-               return NULL;
-       } else {
-               pkg_type++;
-       }
-
-       if (strcmp(pkg_type, "tep") != 0)
-               return NULL;
-
-       tmp = strrchr(pkg_file, '-');
-       if (tmp == NULL || strlen(tmp) == 0) {
-               printf("Invalid tep file name!!!\n");
-               return NULL;
-       }
-
-       pkgid_len = tmp - pkg_file;
-       pkgid = calloc(1, pkgid_len + 1);
-       if (pkgid == NULL) {
-               printf("Insufficient Memory\n");
-               return NULL;
-       }
-       memcpy((void *)pkgid, (const void *)pkg_file, pkgid_len);
-
-       return pkgid;
-}
-
 static void __print_usage()
 {
        printf("\nPackage Manager Tool Version: %s\n\n", PKG_TOOL_VERSION);
@@ -554,7 +510,6 @@ static int __process_request(uid_t uid)
        char pkg_old[PATH_MAX] = {0, };
        char pkg_new[PATH_MAX] = {0, };
        bool blacklist;
-       pkgmgrinfo_pkginfo_h pkginfo;
 
 #if !GLIB_CHECK_VERSION(2,35,0)
        g_type_init();
@@ -1204,7 +1159,10 @@ int main(int argc, char *argv[])
                        if (optarg) {
                                strncpy(data.pkg_old, optarg, PATH_MAX - 1);
                        }
-                       realpath(data.pkg_old, data.resolved_path_pkg_old);
+                       if (realpath(data.pkg_old, data.resolved_path_pkg_old) == NULL) {
+                               printf("failed to set realpath\n");
+                               return -1;
+                       }
                        printf("pkg_old abs path is %s\n", data.resolved_path_pkg_old);
                        break;
 
@@ -1212,7 +1170,10 @@ int main(int argc, char *argv[])
                        if (optarg) {
                                strncpy(data.pkg_new, optarg, PATH_MAX - 1);
                        }
-                       realpath(data.pkg_new, data.resolved_path_pkg_new);
+                       if (realpath(data.pkg_new, data.resolved_path_pkg_new) == NULL) {
+                               printf("failed to set realpath\n");
+                               return -1;
+                       }
                        printf("pkg_new abs path is %s\n", data.resolved_path_pkg_new);
                        break;
 
@@ -1221,7 +1182,10 @@ int main(int argc, char *argv[])
                                strncpy(data.delta_pkg, optarg, PATH_MAX - 1);
                        }
                        printf("delta_pkg is %s\n", data.delta_pkg);
-                       realpath(data.delta_pkg, data.resolved_path_delta_pkg);
+                       if (realpath(data.delta_pkg, data.resolved_path_delta_pkg) == NULL) {
+                               printf("failed to set realpath\n");
+                               return -1;
+                       }
                        printf("delta_pkg abs path is %s\n",data.resolved_path_delta_pkg);
                        break;
                case 'd':  /* descriptor path */
index 9c0ecac..1dfcb8e 100644 (file)
@@ -26,6 +26,8 @@
 #include <dirent.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <errno.h>
 
 #include <pkgmgr_parser.h>
@@ -84,7 +86,12 @@ static int _initdb_load_directory(uid_t uid, const char *directory)
 
                pid_t pid = fork();
                if (pid == 0) {
-                       setuid(uid);
+                       if (setuid(uid) != 0) {
+                               _E("failed to set uid");
+                               closedir(dir);
+                               return -1;
+                       }
+
                        execl(PKGINSTALLMANIFEST_CMD, PKGINSTALLMANIFEST_CMD, "-x", buf,
                              (char*)NULL);
                } else if (pid < 0) {