Title: [250636] trunk
- Revision
- 250636
- Author
- [email protected]
- Date
- 2019-10-02 16:20:56 -0700 (Wed, 02 Oct 2019)
Log Message
DoubleToStringConverter::ToExponential() should null terminate its string.
https://bugs.webkit.org/show_bug.cgi?id=202492
<rdar://problem/55907708>
Reviewed by Filip Pizlo.
JSTests:
* stress/dtoa-AddSubstring-should-uses-strnlen-in-assertion.js: Added.
Source/WTF:
* wtf/dtoa/double-conversion.cc:
- DoubleToStringConverter::DoubleToAscii() always produces a null terminated
string. Fixed the padding loop in DoubleToStringConverter::ToExponential()
that follows it to also keep the null terminator.
* wtf/dtoa/utils.h:
(WTF::double_conversion::StringBuilder::AddSubstring):
- An assertion in here was using strlen() which indicates that it expects a null
terminator in the incoming string. However, this requirement is too restrictive.
The code does not actually depend on the string having a null terminator, only
that a null terminator does not manifest before the nth character. Changed
the assertion to use strnlen() instead to reflect this.
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (250635 => 250636)
--- trunk/JSTests/ChangeLog 2019-10-02 22:41:59 UTC (rev 250635)
+++ trunk/JSTests/ChangeLog 2019-10-02 23:20:56 UTC (rev 250636)
@@ -1,3 +1,13 @@
+2019-10-02 Mark Lam <[email protected]>
+
+ DoubleToStringConverter::ToExponential() should null terminate its string.
+ https://bugs.webkit.org/show_bug.cgi?id=202492
+ <rdar://problem/55907708>
+
+ Reviewed by Filip Pizlo.
+
+ * stress/dtoa-AddSubstring-should-uses-strnlen-in-assertion.js: Added.
+
2019-10-02 Yusuke Suzuki <[email protected]>
[JSC] AsyncGenerator should have internal fields
Added: trunk/JSTests/stress/dtoa-AddSubstring-should-uses-strnlen-in-assertion.js (0 => 250636)
--- trunk/JSTests/stress/dtoa-AddSubstring-should-uses-strnlen-in-assertion.js (rev 0)
+++ trunk/JSTests/stress/dtoa-AddSubstring-should-uses-strnlen-in-assertion.js 2019-10-02 23:20:56 UTC (rev 250636)
@@ -0,0 +1,5 @@
+//@ runDefault
+
+function foo() {}
+foo((0).toExponential(0));
+(0).toExponential(95);
Modified: trunk/Source/WTF/ChangeLog (250635 => 250636)
--- trunk/Source/WTF/ChangeLog 2019-10-02 22:41:59 UTC (rev 250635)
+++ trunk/Source/WTF/ChangeLog 2019-10-02 23:20:56 UTC (rev 250636)
@@ -1,3 +1,24 @@
+2019-10-02 Mark Lam <[email protected]>
+
+ DoubleToStringConverter::ToExponential() should null terminate its string.
+ https://bugs.webkit.org/show_bug.cgi?id=202492
+ <rdar://problem/55907708>
+
+ Reviewed by Filip Pizlo.
+
+ * wtf/dtoa/double-conversion.cc:
+ - DoubleToStringConverter::DoubleToAscii() always produces a null terminated
+ string. Fixed the padding loop in DoubleToStringConverter::ToExponential()
+ that follows it to also keep the null terminator.
+
+ * wtf/dtoa/utils.h:
+ (WTF::double_conversion::StringBuilder::AddSubstring):
+ - An assertion in here was using strlen() which indicates that it expects a null
+ terminator in the incoming string. However, this requirement is too restrictive.
+ The code does not actually depend on the string having a null terminator, only
+ that a null terminator does not manifest before the nth character. Changed
+ the assertion to use strnlen() instead to reflect this.
+
2019-10-02 Zan Dobersek <[email protected]>
[Nicosia] Enable async scrolling at build-time for Nicosia-using ports
Modified: trunk/Source/WTF/wtf/dtoa/double-conversion.cc (250635 => 250636)
--- trunk/Source/WTF/wtf/dtoa/double-conversion.cc 2019-10-02 22:41:59 UTC (rev 250635)
+++ trunk/Source/WTF/wtf/dtoa/double-conversion.cc 2019-10-02 23:20:56 UTC (rev 250636)
@@ -267,10 +267,12 @@
&sign, &decimal_rep_length, &decimal_point);
ASSERT(decimal_rep_length <= requested_digits + 1);
- for (int i = decimal_rep_length; i < requested_digits + 1; ++i) {
- decimal_rep[i] = '0';
+ if (decimal_rep_length < requested_digits + 1) {
+ for (int i = decimal_rep_length; i < requested_digits + 1; ++i)
+ decimal_rep[i] = '0';
+ decimal_rep_length = requested_digits + 1;
+ decimal_rep[decimal_rep_length] = '\0';
}
- decimal_rep_length = requested_digits + 1;
}
bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0);
Modified: trunk/Source/WTF/wtf/dtoa/utils.h (250635 => 250636)
--- trunk/Source/WTF/wtf/dtoa/utils.h 2019-10-02 22:41:59 UTC (rev 250635)
+++ trunk/Source/WTF/wtf/dtoa/utils.h 2019-10-02 23:20:56 UTC (rev 250636)
@@ -271,7 +271,7 @@
// builder. The input string must have enough characters.
void AddSubstring(const char* s, int n) {
ASSERT(!is_finalized() && position_ + n < buffer_.length());
- ASSERT_WITH_SECURITY_IMPLICATION(static_cast<size_t>(n) <= strlen(s));
+ ASSERT_WITH_SECURITY_IMPLICATION(static_cast<size_t>(n) <= strnlen(s, n));
memmove(&buffer_[position_], s, n * kCharSize);
position_ += n;
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes