security check : null termination check
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / builder-filesystem.h
old mode 100644 (file)
new mode 100755 (executable)
index b3fa958..d7118dd
@@ -1,23 +1,28 @@
 #ifndef __DALI_TOOLKIT_INTERNAL_BUILDER_FILESYSTEM_H__
 #define __DALI_TOOLKIT_INTERNAL_BUILDER_FILESYSTEM_H__
 
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // EXTERNAL INCLUDES
+#include <string>
+#include <fstream>
+#include <sstream>
+
 #include <wordexp.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -41,8 +46,16 @@ inline std::string ExpandPath(const std::string &name)
 inline std::string ExePath(void)
 {
   char buf[256];
-  readlink("/proc/self/exe", buf, sizeof(buf));
+  ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
+  len = len > 0 ? len : 0;
+  buf[len] = '\0';
   return std::string(buf);
 }
 
+inline std::string GetFileContents(const std::string &fn)
+{
+  std::ifstream t(fn.c_str());
+  return std::string((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
+}
+
 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_FILESYSTEM_H__