Fix usage of realpath 73/154873/2
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 11 Oct 2017 10:08:12 +0000 (19:08 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 11 Oct 2017 10:54:21 +0000 (19:54 +0900)
NULL is recommended for the second parameter of realpath() because of
buffer overflow.

Change-Id: I21de69b08f17c7ec3262729ec09334f16247ec84
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
plugin/app2sd/server/app2sd_internals_utils.c

index aa3abb6..f7bbd9e 100644 (file)
@@ -135,8 +135,7 @@ void _app2sd_delete_symlink(const char *dirname)
        DIR *dp;
        struct dirent *ep;
        char abs_filename[FILENAME_MAX];
-       char mmc_path[PATH_MAX];
-       char *path;
+       char *mmc_path;
 
        dp = opendir(dirname);
        if (dp == NULL)
@@ -149,12 +148,17 @@ void _app2sd_delete_symlink(const char *dirname)
                /* get realpath find symlink to ".mmc" and unlink it */
                snprintf(abs_filename, sizeof(abs_filename), "%s/%s", dirname,
                                ep->d_name);
-               path = realpath(abs_filename, mmc_path);
-               if (!path)
+               mmc_path = realpath(abs_filename, NULL);
+               if (!mmc_path) {
                        _E("realpath failed");
+                       continue;
+               }
 
-               if (strstr(mmc_path, ".mmc") == NULL)
+               if (strstr(mmc_path, ".mmc") == NULL) {
+                       free(mmc_path);
                        continue;
+               }
+               free(mmc_path);
 
                _E("force unlink [%s]", abs_filename);
                if (unlink(abs_filename)) {