1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Bug #59241 invalid memory read in do_div_mod with doubly assigned variables

Fix: copy my_decimal by value, to avoid dangling pointers.
This commit is contained in:
Tor Didriksen
2011-01-14 10:05:14 +01:00
parent cfa9a4bde6
commit 8dfab82ee0
7 changed files with 44 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2005-2006 MySQL AB
/* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -102,6 +102,24 @@ class my_decimal :public decimal_t
public:
my_decimal(const my_decimal &rhs) : decimal_t(rhs)
{
for (uint i= 0; i < DECIMAL_BUFF_LENGTH; i++)
buffer[i]= rhs.buffer[i];
fix_buffer_pointer();
}
my_decimal& operator=(const my_decimal &rhs)
{
if (this == &rhs)
return *this;
decimal_t::operator=(rhs);
for (uint i= 0; i < DECIMAL_BUFF_LENGTH; i++)
buffer[i]= rhs.buffer[i];
fix_buffer_pointer();
return *this;
}
void init()
{
len= DECIMAL_BUFF_LENGTH;
@ -248,7 +266,6 @@ inline
void my_decimal2decimal(const my_decimal *from, my_decimal *to)
{
*to= *from;
to->fix_buffer_pointer();
}