revise security logic and code quality
authorYoungjae Shin <yj99.shin@samsung.com>
Wed, 20 May 2020 07:58:33 +0000 (16:58 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 15 Jun 2020 07:21:51 +0000 (16:21 +0900)
Change-Id: I7bd4b2069041ab8a0c5fe62fe1ed7d26578615f5

client/CMakeLists.txt
client/modes.pc.in
common/definitions.h
supervisor/XMLGenerator.cpp
tests/modes_test_main.cpp

index 1b267fbf7a8e10b839939789f351af9722737726..b506fbd03db79bea9f236a97385aca17024e51cd 100644 (file)
@@ -16,6 +16,5 @@ TARGET_LINK_LIBRARIES(${CLIENT}       ${client_pkgs_LIBRARIES})
 SET_TARGET_PROPERTIES(${CLIENT} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER})
 INSTALL(TARGETS ${CLIENT} DESTINATION ${LIB_INSTALL_DIR})
 
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 CONFIGURE_FILE(${CLIENT}.pc.in ${CLIENT}.pc @ONLY)
 INSTALL(FILES ${CLIENT}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
index c19de416c7a25d55f971d82260876c5805cf7c81..edaa360b69000bb153047a4089f36f6fe733b9ab 100644 (file)
@@ -6,6 +6,6 @@ includedir=@INCLUDE_INSTALL_DIR@/@CLIENT@
 Name: @LIB@
 Description: Mode Supervisor Client
 Version: @FULLVER@
-Requires:
+Requires: capi-base-common
 Libs: -L${libdir} -l@CLIENT@
 Cflags: -I${includedir}
index ea601a66f0556d6d553b34a0abf9f913d39e4292..994b4c5193aaf80ea9e13e605c459038f79e3401 100644 (file)
@@ -30,7 +30,7 @@
 #define MODES_NAMESPACE_USE using namespace ModeSupervisorNamespace
 
 #ifndef MODES_PLUGIN_DEFAULT_DIR
-#define MODES_PLUGIN_DEFAULT_DIR "/usr/lib/modes-plugins/"
+#define MODES_PLUGIN_DEFAULT_DIR "/usr/lib/modes-plugins"
 #warning "MODES_PLUGIN_DEFAULT_DIR is redefined"
 #endif
 #define MODES_PLUGIN_LIB_PREFIX "libmodes-plugin"
index a43d23edba432cdded960b0bf300cd2f5ec6aa5a..814190daa1893ebb3d3e555888285447914dd35d 100644 (file)
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <stdio.h>
 #include <libxml/tree.h>
 #include <libxml/xmlschemas.h>
 #include "Action.h"
@@ -44,15 +45,21 @@ void XMLGenerator::createRootNode()
        return;
 }
 
-void XMLGenerator::saveToFile(const std::string &filename)
+void XMLGenerator::saveToFile(const std::string &path)
 {
-       int ret = xmlSaveFormatFile(filename.c_str(), doc, 1);
+       //check validation of file : It should be nothing
+       FILE *file = fopen(path.c_str(), "wx");
+       if (nullptr == file) {
+               ERR("Abnormal Situation!! File(%s) exist", path.c_str());
+               throw ModesEx(ModesEx::SYSTEM_ERROR);
+       }
+
+       int ret = xmlDocFormatDump(file, doc, 1);
+       fclose(file);
        if (-1 == ret) {
-               ERR("xmlSaveFormatFile(%s) Fail()", filename.c_str());
+               ERR("xmlSaveFormatFile(%s) Fail(%d)", path.c_str(), errno);
                throw ModesEx(ModesEx::INVALID_ARG);
        }
-
-       return;
 }
 
 const std::string XMLGenerator::getModeTypeStr(Mode::ModeType t)
@@ -73,11 +80,6 @@ void XMLGenerator::makeModeXML(const std::string &path, const Mode &mode)
                throw ModesEx(ModesEx::INVALID_ARG);
        }
 
-       if (0 != remove(path.c_str()) && ENOENT != errno) {
-               ERR("remove(%s) Fail(%d)", path.c_str(), errno);
-               throw ModesEx(ModesEx::SYSTEM_ERROR);
-       }
-
        createRootNode();
 
        const std::string modeType = getModeTypeStr(mode.getModeType());
index e7484bd1db3d6017c2356c698626a76e9a277b15..9d1a7ca6f96b26004256297c4f96cd04aca68821 100644 (file)
@@ -16,6 +16,6 @@
 #include <gtest/gtest.h>
 
 int main(int argc, char **argv) {
-       testing::InitGoogleTest(&argc, argv);
+       ::testing::InitGoogleTest(&argc, argv);
        return RUN_ALL_TESTS();
 }