Replace open(system call) to access(std.) 95/216695/8 accepted/tizen/unified/20191111.105532 submit/tizen/20191110.224221
authorjiyong.min <jiyong.min@samsung.com>
Thu, 31 Oct 2019 01:28:43 +0000 (10:28 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 4 Nov 2019 00:52:35 +0000 (09:52 +0900)
 - When open() without O_CREAT, executable program can't create file
   due to 'Permission Denied'. Just it happened in shell enviroment.

 - The access() is standard function to check path permission.

Change-Id: I5f4f2bf00c0e6a21b36c1c39261008e5035113fe

include/image_util_private.h
src/image_util_encode.c
src/image_util_private.c

index 67277c8..066e5e4 100644 (file)
@@ -210,7 +210,7 @@ unsigned int _get_number_of_colorspace(void);
 int _convert_type_of_colorspace(const image_util_colorspace_e colorspace);
 int _convert_type_of_colorspace_with_image_type(const image_util_colorspace_e colorspace, const image_util_type_e type);
 
-int _check_valid_file(const char *path, int mode);
+int _check_encode_path(const char *path);
 int _image_error_capi(int error_code);
 
 int _image_util_image_to_packet(image_util_image_h image, media_packet_h *packet);
index dc9d6b4..9bf4924 100644 (file)
@@ -365,7 +365,7 @@ static int __image_util_encode_run_to_file(image_util_encode_h handle, image_uti
 
        image_util_retvm_if(!_handle, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
        image_util_retvm_if(!image, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image");
-       ret = _check_valid_file(file_path, O_WRONLY);
+       ret = _check_encode_path(file_path);
        image_util_retvm_if(ret != IMAGE_UTIL_ERROR_NONE, ret, "_check_valid_file failed (%d)", ret);
 
        image_util_sec_debug("Image type [%d]. Save to file_path [%s]", _handle->image_type, file_path);
@@ -575,7 +575,7 @@ int image_util_encode_run_async_to_file(image_util_encode_h handle, image_util_i
        image_util_retvm_if(!_handle, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle");
        image_util_retvm_if(!image, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image");
        image_util_retvm_if(!completed_cb, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid completed_cb");
-       ret = _check_valid_file(file_path, O_WRONLY);
+       ret = _check_encode_path(file_path);
        image_util_retvm_if(ret != IMAGE_UTIL_ERROR_NONE, ret, "_check_valid_file failed (%d)", ret);
 
        image_util_fenter();
index 1d5f883..9435e0c 100755 (executable)
@@ -214,27 +214,27 @@ int _convert_type_of_colorspace_with_image_type(const image_util_colorspace_e co
        return new_colorspace;
 }
 
-int _check_valid_file(const char *path, int mode)
+int _check_encode_path(const char *path)
 {
-       int ret = IMAGE_UTIL_ERROR_NONE;
-       int fd = 0;
+       int ret = 0;
+       char *dirname = NULL;
 
        image_util_retvm_if(!path, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid path");
 
-       fd = open(path, mode);
+       dirname = g_path_get_dirname(path);
+       image_util_retvm_if(!dirname, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid path");
 
-       if (fd < 0) {
+       if (access(dirname, W_OK) != 0) {
                if (errno == EACCES || errno == EPERM) {
-                       image_util_error("Fail to open path[%s]: Permission Denied", path);
+                       image_util_error("Fail to access path[%s]: Permission Denied", path);
                        ret = IMAGE_UTIL_ERROR_PERMISSION_DENIED;
                } else {
-                       image_util_error("Fail to open path[%s]: Invalid Path", path);
+                       image_util_error("Fail to access path[%s]: Invalid Path", path);
                        ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
                }
-       } else {
-               close(fd);
        }
 
+       g_free(dirname);
        return ret;
 }