summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorTor Didriksen <tor.didriksen@oracle.com>2011-09-21 13:46:49 +0200
committerTor Didriksen <tor.didriksen@oracle.com>2011-09-21 13:46:49 +0200
commit8d1c4bba678102bf8293e63319371734b7e5c7b2 (patch)
tree1eade62487542ed0bf86b4d6582d57e8c11f2a71 /strings
parent0f359571c5ade4acca6b58bb9c0603ed63cb4da1 (diff)
downloadmariadb-git-8d1c4bba678102bf8293e63319371734b7e5c7b2.tar.gz
Bug#12985030 SIMPLE QUERY WITH DECIMAL NUMBERS LEAKS MEMORY
Extra fix: 'if (p5 < p5_a + P5A_MAX)' is not portable. p5 starts out pointing to a static array, then may point to a buffer on the stack, then may point to malloc()ed memory.
Diffstat (limited to 'strings')
-rw-r--r--strings/dtoa.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/strings/dtoa.c b/strings/dtoa.c
index 05c9bb6e529..f7c38b2420d 100644
--- a/strings/dtoa.c
+++ b/strings/dtoa.c
@@ -1009,6 +1009,7 @@ static Bigint *pow5mult(Bigint *b, int k, Stack_alloc *alloc)
Bigint *b1, *p5, *p51=NULL;
int i;
static int p05[3]= { 5, 25, 125 };
+ my_bool overflow= FALSE;
if ((i= k & 3))
b= multadd(b, p05[i-1], 0, alloc);
@@ -1027,16 +1028,19 @@ static Bigint *pow5mult(Bigint *b, int k, Stack_alloc *alloc)
if (!(k>>= 1))
break;
/* Calculate next power of 5 */
- if (p5 < p5_a + P5A_MAX)
- ++p5;
- else if (p5 == p5_a + P5A_MAX)
- p5= mult(p5, p5, alloc);
- else
+ if (overflow)
{
p51= mult(p5, p5, alloc);
Bfree(p5, alloc);
p5= p51;
}
+ else if (p5 < p5_a + P5A_MAX)
+ ++p5;
+ else if (p5 == p5_a + P5A_MAX)
+ {
+ p5= mult(p5, p5, alloc);
+ overflow= TRUE;
+ }
}
if (p51)
Bfree(p51, alloc);