From 9c4532473639a9a2f8002975bd7c1468ab86fe25 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Mon, 12 Feb 2018 18:10:02 +0900 Subject: [PATCH] helper: correct symbolic check function Change-Id: Id52e6ed434ae6a2aba926362a2ce02bf58b5788d --- src/tdm_helper.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/tdm_helper.c b/src/tdm_helper.c index cd6426f..a1b7427 100644 --- a/src/tdm_helper.c +++ b/src/tdm_helper.c @@ -61,26 +61,20 @@ tdm_helper_get_time(void) } static int -_tdm_helper_check_file_is_valid(const char* path, int del_link) +_tdm_helper_check_file_is_symbolic_link(const char* path) { - char *real_path; + struct stat sb; if (!path) return 0; - real_path = realpath(path, NULL); - if (real_path && strncmp(path, real_path, strlen(path))) { - if (del_link) - unlink(path); - free(real_path); - + if (stat(path, &sb) != 0) return 0; - } - if (real_path) - free(real_path); + if (S_ISLNK(sb.st_mode)) + return 1; - return 1; + return 0; } static void @@ -90,8 +84,10 @@ _tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2, unsigned int *blocks; FILE *fp; - if (!_tdm_helper_check_file_is_valid(file, 1)) - TDM_WRN("'%s' may be symbolic link\n", file); + if (_tdm_helper_check_file_is_symbolic_link(file)) { + TDM_ERR("'%s' may be symbolic link\n", file); + return; + } fp = fopen(file, "w+"); TDM_RETURN_IF_FAIL(fp != NULL); @@ -118,8 +114,10 @@ _tdm_helper_dump_png(const char *file, const void *data, int width, { FILE *fp; - if (!_tdm_helper_check_file_is_valid(file, 1)) - TDM_WRN("'%s' may be symbolic link\n", file); + if (_tdm_helper_check_file_is_symbolic_link(file)) { + TDM_ERR("'%s' may be symbolic link\n", file); + return; + } fp = fopen(file, "wb"); TDM_RETURN_IF_FAIL(fp != NULL); -- 2.7.4