Check pos variable before using substr() function 01/161801/3
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 27 Nov 2017 11:16:04 +0000 (20:16 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 30 Nov 2017 04:50:59 +0000 (04:50 +0000)
Change-Id: I8a5ebfb3fcbe5936e336da2751178f6cf03165b8

ism/src/scim_helper.cpp

index 9c26674..2a79425 100644 (file)
@@ -2057,9 +2057,12 @@ HelperAgent::get_surrounding_text (int maxlen_before, int maxlen_after, String &
             String buffer = m_impl->finalized_text;
             cursor = m_impl->finalized_cursor_pos;
             int pos = cursor - maxlen_before;
+            if (maxlen_before < 0) pos = 0;
+            if (pos > (int)buffer.length()) pos = (int)buffer.length();
             if (pos < 0) pos = 0;
             int len = maxlen_after + (cursor - pos);
-            if (len < 0) len = INT_MAX;
+            if (len < 0) len = 0;
+            if (maxlen_after < 0 ) len = String::npos;
             text = buffer.substr (pos, len);
         } else {
             text.clear ();