Fixing bug 328778. Make the UA string we pass to plugins be terminated at the last space or at max length if the string doesn't fit rather that just returning NULL. r+sr=jst@mozilla.org
authorKathleen Brade <brade@comcast.net>
Mon, 04 Aug 2008 14:24:50 -0700
changeset 16368 3884f9437753
parent 16367 b3954e41f988
child 16369 8666db48bea6
push id976
push userjst@mozilla.com
push date2008-08-04 21:25 +0000
treeherdermozilla-central@3884f9437753 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs328778
milestone1.9.1a2pre
Fixing bug 328778. Make the UA string we pass to plugins be terminated at the last space or at max length if the string doesn't fit rather that just returning NULL. r+sr=jst@mozilla.org
modules/plugin/base/src/nsPluginHostImpl.cpp
--- a/modules/plugin/base/src/nsPluginHostImpl.cpp
+++ b/modules/plugin/base/src/nsPluginHostImpl.cpp
@@ -2916,25 +2916,34 @@ nsresult nsPluginHostImpl::UserAgent(con
     return res;
 
   nsCAutoString uaString;
   res = http->GetUserAgent(uaString);
 
   if (NS_SUCCEEDED(res))
   {
     if(NS_RETURN_UASTRING_SIZE > uaString.Length())
-    {
       PL_strcpy(resultString, uaString.get());
-      *retstring = resultString;
-    }
     else
     {
-      *retstring = nsnull;
-      res = NS_ERROR_OUT_OF_MEMORY;
+      // Copy as much of UA string as we can (terminate at right-most space).
+      PL_strncpy(resultString, uaString.get(), NS_RETURN_UASTRING_SIZE);
+      for (int i = NS_RETURN_UASTRING_SIZE - 1; i >= 0; i--)
+      {
+        if (0 == i)
+          resultString[NS_RETURN_UASTRING_SIZE - 1] = '\0';
+        else if (resultString[i] == ' ')
+        {
+          resultString[i] = '\0';
+          break;
+        }
+      }
     }
+
+    *retstring = resultString;
   }
   else
     *retstring = nsnull;
 
   PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsPluginHostImpl::UserAgent return=%s\n", *retstring));
 
   return res;
 }