Title: [241856] trunk/Source/WTF
Revision
241856
Author
[email protected]
Date
2019-02-20 17:36:04 -0800 (Wed, 20 Feb 2019)

Log Message

URL percent-encode operations should use checked arithmetic for buffer allocation length
https://bugs.webkit.org/show_bug.cgi?id=194877
<rdar://problem/48212062>

Patch by Alex Christensen <[email protected]> on 2019-02-20
Reviewed by Tim Horton.

* wtf/URLHelpers.cpp:
(WTF::URLHelpers::userVisibleURL):
* wtf/cocoa/NSURLExtras.mm:
(WTF::dataWithUserTypedString):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (241855 => 241856)


--- trunk/Source/WTF/ChangeLog	2019-02-21 01:25:46 UTC (rev 241855)
+++ trunk/Source/WTF/ChangeLog	2019-02-21 01:36:04 UTC (rev 241856)
@@ -1,3 +1,16 @@
+2019-02-20  Alex Christensen  <[email protected]>
+
+        URL percent-encode operations should use checked arithmetic for buffer allocation length
+        https://bugs.webkit.org/show_bug.cgi?id=194877
+        <rdar://problem/48212062>
+
+        Reviewed by Tim Horton.
+
+        * wtf/URLHelpers.cpp:
+        (WTF::URLHelpers::userVisibleURL):
+        * wtf/cocoa/NSURLExtras.mm:
+        (WTF::dataWithUserTypedString):
+
 2019-02-20  Dean Jackson  <[email protected]>
 
         Rotation animations sometimes use the wrong origin (affects apple.com)

Modified: trunk/Source/WTF/wtf/URLHelpers.cpp (241855 => 241856)


--- trunk/Source/WTF/wtf/URLHelpers.cpp	2019-02-21 01:25:46 UTC (rev 241855)
+++ trunk/Source/WTF/wtf/URLHelpers.cpp	2019-02-21 01:36:04 UTC (rev 241856)
@@ -808,9 +808,11 @@
 
     bool mayNeedHostNameDecoding = false;
 
-    // The buffer should be large enough to %-escape every character.
-    int bufferLength = (length * 3) + 1;
-    Vector<char, urlBytesBufferLength> after(bufferLength);
+    Checked<int, RecordOverflow> bufferLength = length;
+    bufferLength = bufferLength * 3 + 1; // The buffer should be large enough to %-escape every character.
+    if (bufferLength.hasOverflowed())
+        return { };
+    Vector<char, urlBytesBufferLength> after(bufferLength.unsafeGet());
 
     char* q = after.data();
     {
@@ -850,7 +852,7 @@
         // then we will copy back bytes to the start of the buffer 
         // as we convert.
         int afterlength = q - after.data();
-        char* p = after.data() + bufferLength - afterlength - 1;
+        char* p = after.data() + bufferLength.unsafeGet() - afterlength - 1;
         memmove(p, after.data(), afterlength + 1); // copies trailing '\0'
         char* q = after.data();
         while (*p) {

Modified: trunk/Source/WTF/wtf/cocoa/NSURLExtras.mm (241855 => 241856)


--- trunk/Source/WTF/wtf/cocoa/NSURLExtras.mm	2019-02-21 01:25:46 UTC (rev 241855)
+++ trunk/Source/WTF/wtf/cocoa/NSURLExtras.mm	2019-02-21 01:36:04 UTC (rev 241856)
@@ -194,8 +194,13 @@
     int inLength = [userTypedData length];
     if (!inLength)
         return nil;
+
+    Checked<int, RecordOverflow> mallocLength = inLength;
+    mallocLength *= 3; // large enough to %-escape every character
+    if (mallocLength.hasOverflowed())
+        return nil;
     
-    char* outBytes = static_cast<char *>(malloc(inLength * 3)); // large enough to %-escape every character
+    char* outBytes = static_cast<char *>(malloc(mallocLength.unsafeGet()));
     char* p = outBytes;
     int outLength = 0;
     for (int i = 0; i < inLength; i++) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to