[Win] Always NULL-terminate the string in createUTF8String()
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Jun 2014 01:10:48 +0000 (01:10 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Jun 2014 01:10:48 +0000 (01:10 +0000)
<http://webkit.org/b/134353>
<rdar://problem/17471783>

Reviewed by Brent Fulgham.

* plugins/PluginView.cpp:
(WebCore::createUTF8String): Pull out CString length into local
variable.  Switch to use memcpy.  Always NULL-terminate the
string.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170513 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/plugins/PluginView.cpp

index 0291fb64617ab31d83bb705cb32c8eb510c57e2d..8453611cbbdda4db430c2af695bf022ad0d47666 100644 (file)
@@ -1,3 +1,16 @@
+2014-06-26  David Kilzer  <ddkilzer@apple.com>
+
+        [Win] Always NULL-terminate the string in createUTF8String()
+        <http://webkit.org/b/134353>
+        <rdar://problem/17471783>
+
+        Reviewed by Brent Fulgham.
+
+        * plugins/PluginView.cpp:
+        (WebCore::createUTF8String): Pull out CString length into local
+        variable.  Switch to use memcpy.  Always NULL-terminate the
+        string.
+
 2014-06-26  Jer Noble  <jer.noble@apple.com>
 
         [MSE][Mac] Crash in WebCore::MediaPlayerPrivateMediaSourceAVFObjC::buffered const + 13
index d73c66c62bd7f4faa98e75e226cfcf7dfa39e378..6bb40a5dcf1da5c32a308a2a0cccc1fdfe2b98f3 100644 (file)
@@ -409,9 +409,11 @@ PluginView* PluginView::currentPluginView()
 static char* createUTF8String(const String& str)
 {
     CString cstr = str.utf8();
-    char* result = reinterpret_cast<char*>(fastMalloc(cstr.length() + 1));
+    const size_t cstrLength = cstr.length();
+    char* result = reinterpret_cast<char*>(fastMalloc(cstrLength + 1));
 
-    strncpy(result, cstr.data(), cstr.length() + 1);
+    memcpy(result, cstr.data(), cstrLength);
+    result[cstrLength] = '\0';
 
     return result;
 }