[3.0] Fix Svace issues 30/76930/3 accepted/tizen/common/20160629.223338 accepted/tizen/ivi/20160630.003707 accepted/tizen/mobile/20160630.003637 accepted/tizen/tv/20160630.003609 accepted/tizen/wearable/20160630.003800 submit/tizen/20160629.094059
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Tue, 28 Jun 2016 04:41:20 +0000 (13:41 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Wed, 29 Jun 2016 06:02:12 +0000 (15:02 +0900)
- Return value of a function GetMap() has to be checked for NULL at shader-impl.cpp
- Use 'rand_r' function instead of vulnerable function 'rand' at random.h

Change-Id: Ib28207bcb87b073eea34887233514c31958c11f1

dali/internal/event/rendering/shader-impl.cpp
dali/public-api/math/random.h

index 698a03b..127de82 100644 (file)
@@ -168,29 +168,32 @@ void Shader::SetDefaultProperty( Property::Index index,
       if( propertyValue.GetType() == Property::MAP )
       {
         Dali::Property::Map* map = propertyValue.GetMap();
-        std::string vertex;
-        std::string fragment;
-        Dali::Shader::ShaderHints hints(Dali::Shader::HINT_NONE);
-
-        if( Property::Value* value = map->Find("vertex") )
-        {
-          vertex = value->Get<std::string>();
-        }
-
-        if( Property::Value* value = map->Find("fragment") )
+        if( map )
         {
-          fragment = value->Get<std::string>();
+          std::string vertex;
+          std::string fragment;
+          Dali::Shader::ShaderHints hints(Dali::Shader::HINT_NONE);
+
+          if( Property::Value* value = map->Find("vertex") )
+          {
+            vertex = value->Get<std::string>();
+          }
+
+          if( Property::Value* value = map->Find("fragment") )
+          {
+            fragment = value->Get<std::string>();
+          }
+
+          if( Property::Value* value = map->Find("hints") )
+          {
+            static_cast<void>( // ignore return
+              Scripting::GetEnumeration< Dali::Shader::ShaderHints >(value->Get<std::string>().c_str(),
+                                                                     ShaderHintsTable, ShaderHintsTableSize, hints)
+              );
+          }
+
+          Initialize(vertex, fragment, hints );
         }
-
-        if( Property::Value* value = map->Find("hints") )
-        {
-          static_cast<void>( // ignore return
-            Scripting::GetEnumeration< Dali::Shader::ShaderHints >(value->Get<std::string>().c_str(),
-                                                                   ShaderHintsTable, ShaderHintsTableSize, hints)
-            );
-        }
-
-        Initialize(vertex, fragment, hints );
       }
       else
       {
index 5ba0c95..394b2dd 100644 (file)
@@ -35,6 +35,11 @@ namespace Dali
 namespace Random
 {
 
+namespace
+{
+  __thread unsigned int seed;
+}
+
 /**
  * @brief Returns a random number between f0 and f1.
  *
@@ -46,9 +51,10 @@ namespace Random
  */
 inline float Range(float f0, float f1)
 {
+  seed = time(NULL);
   float min = std::min(f0, f1);
   float max = std::max(f0, f1);
-  return min + (rand() & 0xfff) * (max-min) * (1.0f/4095.0f);
+  return min + (rand_r(&seed) & 0xfff) * (max-min) * (1.0f/4095.0f);
 }
 
 /**