Replace strerror with strerror_r 15/247015/1
authorhyunho <hhstark.kang@samsung.com>
Fri, 6 Nov 2020 05:09:06 +0000 (14:09 +0900)
committerhyunho <hhstark.kang@samsung.com>
Fri, 6 Nov 2020 05:10:09 +0000 (14:10 +0900)
strerror_r is a thread safe function

Change-Id: Ib4578f84a1adbc1e6629b41e9e96995706b10922
Signed-off-by: hyunho <hhstark.kang@samsung.com>
notification-ex/shared_file.cc
notification/src/notification_shared_file.c

index 99f2c44..cdc9382 100644 (file)
@@ -41,6 +41,7 @@
 #define LOG_TAG "NOTIFICATION_EX"
 #define CHECK_LABEL "::RO"
 #define NOTI_PRIV_DATA_DIR "data/.notification_ex"
+#define ERR_BUFFER_SIZE 1024
 
 using namespace std;
 
@@ -184,6 +185,7 @@ vector<char*> SharedFile::ConvertListToArray(const list<string>& data) {
 bool SharedFile::IsPrivatePath(string path) const {
   char* smack_label = nullptr;
   bool ret = false;
+  char err_buf[ERR_BUFFER_SIZE];
 
   if (path.empty()) {
     LOGE("Invalid parameter");
@@ -194,7 +196,7 @@ bool SharedFile::IsPrivatePath(string path) const {
   if (smack_new_label_from_path(path.c_str(), XATTR_NAME_SMACK, 1, &smack_label)
         <= 0) {
     LOGE("smack_new_label_from_path failed  : %d [%s][%s]",
-        errno, strerror(errno), path.c_str());
+        errno, strerror_r(errno, err_buf, sizeof(err_buf)), path.c_str());
     return false;
   }
 
index abbf043..9a585f2 100644 (file)
@@ -40,6 +40,7 @@
 #define NOTI_PRIV_DATA_DIR "data/.notification"
 #define MAX_TIMEOUT 5000
 #define MAX_RETRY_CNT 3
+#define ERR_BUFFER_SIZE 1024
 
 #define DUMMY_PARAM
 #define __OOM_CHECK(value, ret_value, free_fun) \
@@ -687,13 +688,16 @@ char *notification_check_file_path_is_private(const char *pkg_id,
        char *dst_path = NULL;
        int size;
        uid_t uid = getuid();
+       char err_buf[ERR_BUFFER_SIZE];
+       char *err_str;
 
        errno = 0;
        size = smack_new_label_from_path(file_path, XATTR_NAME_SMACK,
                                                        TRUE, &smack_label);
        if (size <= 0) {
-               ERR("Failed to get smack info : %d [%s][%s]",
-                               errno, strerror(errno), file_path);
+               err_str = strerror_r(errno, err_buf, sizeof(err_buf));
+               ERR("Failed to get smack info : %d [%s][%s]", errno, err_str,
+                       file_path);
                return NULL;
        }