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

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