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

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