From 5076baa608858a7085c6bc81a9838de4c7420aa7 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Fri, 20 Sep 2013 12:59:14 +0200 Subject: [PATCH] Fix Prevent issue - Incorrect usage of TEMP_FAILURE_RETRY [Issue#] CID: 22993, 22996, LINUXWRT-906 [Problem] closedir() repeated if EINTR occurrs [Cause] Same as Prevent CID: 22995 https://review.tizendev.org/gerrit/#/c/83449/ * For POSIX closedir() specifies two possible errno values: EBADF, EINTR (see closedir(3p)). * For Linux, on the other hand, only one errno value is specified: EBADF (see closedir(3)). * In fact, closedir() implementation in GNU C Library may set other errno values as well, e.g. EINVAL if value NULL is passed to the function (verified for glibc 2.15, source file sysdeps/unix/closedir.c). * Assuming that closedir() is just a wrapper around a call to close() system call and having in mind that it was decided (and confirmed by Linus Torvalds) that repeating close() even for EINTR is unsafe which I have decided to not repeat closedir() in such case as well. * What's more, implementation of closedir() in GNU C Library calls free() on the stream handle, so repeating closedir() may lead to memory corruption (as reported by Prevent). [Solution] Do not repeat closedir() on error (even EINTR). [SCMRequest] N/A [Verification] Build repository. Change-Id: I857861d1f10954d4c199bf8d54fc5ea13cb00d44 --- src/jobs/widget_install/task_manifest_file.cpp | 2 +- src/jobs/widget_install/task_widget_config.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jobs/widget_install/task_manifest_file.cpp b/src/jobs/widget_install/task_manifest_file.cpp index abd3d02..d89b7a2 100644 --- a/src/jobs/widget_install/task_manifest_file.cpp +++ b/src/jobs/widget_install/task_manifest_file.cpp @@ -595,7 +595,7 @@ void TaskManifestFile::getFileList(const char* path, _E("readdir_r() failed with %s", DPL::GetErrnoString().c_str()); } - if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) { + if (-1 == closedir(dir)) { _E("Failed to close dir: %s with error: %s", path, DPL::GetErrnoString().c_str()); } } diff --git a/src/jobs/widget_install/task_widget_config.cpp b/src/jobs/widget_install/task_widget_config.cpp index 4f5785e..b01067e 100755 --- a/src/jobs/widget_install/task_widget_config.cpp +++ b/src/jobs/widget_install/task_widget_config.cpp @@ -154,7 +154,7 @@ void TaskWidgetConfig::ReadLocaleFolders() _E("readdir_r() failed with %s", DPL::GetErrnoString().c_str()); } - if (-1 == TEMP_FAILURE_RETRY(closedir(localeDir))) { + if (-1 == closedir(localeDir)) { _E("Failed to close dir: %s with error: %s", localePath.c_str(), DPL::GetErrnoString().c_str()); } } -- 2.7.4