Blame SOURCES/sqlite-3.26.0-CVE-2020-13434.patch

d22c23
Subject: [PATCH] Limit the "precision" of floating-point to text conversions
d22c23
 in the printf() function to 100,000,000.
d22c23
d22c23
---
d22c23
 src/printf.c     | 12 ++++++++++++
d22c23
 test/printf.test | 16 +++++++++++++---
d22c23
 2 files changed, 25 insertions(+), 3 deletions(-)
d22c23
d22c23
diff --git a/src/printf.c b/src/printf.c
d22c23
index 7bce83f..260bf79 100644
d22c23
--- a/src/printf.c
d22c23
+++ b/src/printf.c
d22c23
@@ -165,6 +165,13 @@ static char *getTextArg(PrintfArguments *p){
d22c23
 #endif
d22c23
 #define etBUFSIZE SQLITE_PRINT_BUF_SIZE  /* Size of the output buffer */
d22c23
 
d22c23
+/*
d22c23
+** Hard limit on the precision of floating-point conversions.
d22c23
+*/
d22c23
+#ifndef SQLITE_PRINTF_PRECISION_LIMIT
d22c23
+# define SQLITE_FP_PRECISION_LIMIT 100000000
d22c23
+#endif
d22c23
+
d22c23
 /*
d22c23
 ** Render a string given by "fmt" into the StrAccum object.
d22c23
 */
d22c23
@@ -471,6 +478,11 @@ void sqlite3_str_vappendf(
d22c23
         length = 0;
d22c23
 #else
d22c23
         if( precision<0 ) precision = 6;         /* Set default precision */
d22c23
+#ifdef SQLITE_FP_PRECISION_LIMIT
d22c23
+        if( precision>SQLITE_FP_PRECISION_LIMIT ){
d22c23
+          precision = SQLITE_FP_PRECISION_LIMIT;
d22c23
+        }
d22c23
+#endif
d22c23
         if( realvalue<0.0 ){
d22c23
           realvalue = -realvalue;
d22c23
           prefix = '-';
d22c23
diff --git a/test/printf.test b/test/printf.test
d22c23
index d768898..a2b5e2a 100644
d22c23
--- a/test/printf.test
d22c23
+++ b/test/printf.test
d22c23
@@ -538,9 +538,11 @@ do_test printf-2.1.2.8 {
d22c23
 do_test printf-2.1.2.9 {
d22c23
   sqlite3_mprintf_double {abc: %d %d (%1.1g) :xyz} 1 1 1.0e-20
d22c23
 } {abc: 1 1 (1e-20) :xyz}
d22c23
-do_test printf-2.1.2.10 {
d22c23
-  sqlite3_mprintf_double {abc: %*.*f}  2000000000 1000000000 1.0e-20
d22c23
-} {abc: }
d22c23
+if {$SQLITE_MAX_LENGTH<=[expr 1000*1000*1000]} {
d22c23
+  do_test printf-2.1.2.10 {
d22c23
+    sqlite3_mprintf_double {abc: %*.*f}  2000000000 1000000000 1.0e-20
d22c23
+  } {}
d22c23
+}
d22c23
 do_test printf-2.1.3.1 {
d22c23
   sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 1.0
d22c23
 } {abc: (1.0) :xyz}
d22c23
@@ -3777,4 +3779,12 @@ foreach ::iRepeat {0 1} {
d22c23
   }
d22c23
 }
d22c23
 
d22c23
+# 2020-05-23
d22c23
+# ticket 23439ea582241138
d22c23
+#
d22c23
+do_execsql_test printf-16.1 {
d22c23
+  SELECT printf('%.*g',2147483647,0.01);
d22c23
+} {0.01}
d22c23
+
d22c23
+
d22c23
 finish_test
d22c23
-- 
d22c23
2.24.1
d22c23