Fix SVACE / Coverity issue 18/213418/3
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Thu, 5 Sep 2019 06:19:26 +0000 (15:19 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Mon, 9 Sep 2019 02:30:17 +0000 (11:30 +0900)
- After having been compared to NULL value at input-method-context-impl-ecore-wl.cpp:605,
 pointer 'plainText' is dereferenced at 618 line by calling function 'strdup'.

Change-Id: Ieeeda41d8eab2f3310c0a9d58aa8251e70e2cfd7
Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
dali/internal/input/tizen-wayland/input-method-context-impl-ecore-wl.cpp

index 73b1a43..b5bf294 100755 (executable)
@@ -604,33 +604,36 @@ bool InputMethodContextEcoreWl::RetrieveSurrounding( void* data, ImfContext* imf
 
   if( callbackData.update )
   {
+    if( cursorPosition )
+    {
+      mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
+      *cursorPosition = mIMFCursorPosition;
+    }
+
     if( text )
     {
       const char* plainText = callbackData.currentText.c_str();
+
       if( plainText )
       {
+        // The memory allocated by strdup() can be freed by ecore_imf_context_surrounding_get() internally.
+        *text = strdup( plainText );
+
         // If the current input panel is password mode, dali should replace the plain text with '*' (Asterisk) character.
         if( ecore_imf_context_input_hint_get( mIMFContext ) & ECORE_IMF_INPUT_HINT_SENSITIVE_DATA )
         {
-          char* iter = NULL;
-          for( iter = const_cast<char*>( plainText ); iter && *iter; ++iter )
+          for( char* iter = *text; *iter; ++iter )
           {
             *iter = '*';
           }
         }
-      }
-      // The memory allocated by strdup() can be freed by ecore_imf_context_surrounding_get() internally.
-      *text = strdup( plainText );
-    }
 
-    if( cursorPosition )
-    {
-      mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
-      *cursorPosition = mIMFCursorPosition;
+        return EINA_TRUE;
+      }
     }
   }
 
-  return EINA_TRUE;
+  return EINA_FALSE;
 }
 
 /**