Ensure strncmp compare include null-terminate char 85/316085/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 13 Aug 2024 10:43:44 +0000 (19:43 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 14 Aug 2024 02:10:21 +0000 (11:10 +0900)
If we use n-paramater of strncmp as strlen, it will check only
Prefix of string.

For example,
char a[] = "asdf";
char b[] = "as";

then, strncmp(a, b, strlen(b)) will return 0, even if a and b is not equal.

To avoid this kind of problem, let we ensurely check end of comparitor is
delim or not.

Change-Id: I34b10a014cb06721af2cc92df06892bfb20bf6f3
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/text/controller/text-controller.cpp

index 7b87c2f..ae8f63c 100644 (file)
@@ -1802,11 +1802,11 @@ void Controller::PasteClipboardItemEvent(uint32_t id, const char* mimeType, cons
   }
 
   // text-controller allows only plain text type.
-  if(!strncmp(mimeType, MIME_TYPE_TEXT_PLAIN, strlen(MIME_TYPE_TEXT_PLAIN)))
+  if(!strncmp(mimeType, MIME_TYPE_TEXT_PLAIN, strlen(MIME_TYPE_TEXT_PLAIN) + 1 /* Compare include null-terminated char */))
   {
     EventHandler::PasteClipboardItemEvent(*this, data);
   }
-  else if(!strncmp(mimeType, MIME_TYPE_HTML, strlen(MIME_TYPE_HTML)))
+  else if(!strncmp(mimeType, MIME_TYPE_HTML, strlen(MIME_TYPE_HTML) + 1 /* Compare include null-terminated char */))
   {
     // This does not mean that text controls can parse html.
     // This is temporary code, as text controls do not support html type data.