Bug #31253 crash comparing datetime to double
| Submitted: | 27 Sep 2007 18:18 | Modified: | 24 Oct 2007 19:39 |
|---|---|---|---|
| Reporter: | Shane Bester (Platinum Quality Contributor) | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: Data Types | Severity: | S1 (Critical) |
| Version: | 5.1.23, 5.0.48 | OS: | Any |
| Assigned to: | Tatiana Azundris Nuernberg | CPU Architecture: | Any |
| Tags: | crash | ||
[27 Sep 2007 18:18]
Shane Bester
[1 Oct 2007 23:06]
Tatiana Azundris Nuernberg
## BT for crash:
#0 0x085bc814 in decimal2double (from=0x0, to=0xb51c2e58) at decimal.c:958
#1 0x08190606 in my_decimal2double (mask=30, d=0x0, result=0xb51c2e58) at my_decimal.h:280
#2 0x081805c9 in Item::val_real_from_decimal (this=0x8d81068) at item.cc:303
#3 0x081e0bed in Item_datetime_typecast::val_real (this=0x8d81068) at item_timefunc.h:857
#4 0x081b493a in Arg_comparator::compare_real_fixed (this=0x8d811b8) at item_cmpfunc.cc:1087
#5 0x081c3583 in Arg_comparator::compare (this=0x8d811b8) at item_cmpfunc.h:71
#6 0x081b90b1 in Item_func_eq::val_int (this=0x8d81140) at item_cmpfunc.cc:1502
#7 0x08292aa3 in make_join_select (join=0x8d812a0, select=0x8d82530, cond=0x8d81140) at sql_select.cc:5726
## BT leading up to crash
#0 Item::val_decimal_from_date (this=0x8d81088, decimal_value=0xb51f3e20) at item.cc:277
#1 0x081e0a5b in Item_datetime_typecast::val_decimal (this=0x8d81088, decimal_value=0xb51f3e20) at item_timefunc.h:862
#2 0x0818059a in Item::val_real_from_decimal (this=0x8d81088) at item.cc:300
#3 0x081e0bed in Item_datetime_typecast::val_real (this=0x8d81088) at item_timefunc.h:857
#4 0x081b493a in Arg_comparator::compare_real_fixed (this=0x8d811d8) at item_cmpfunc.cc:1087
#5 0x081c3583 in Arg_comparator::compare (this=0x8d811d8) at item_cmpfunc.h:71
#6 0x081b90b1 in Item_func_eq::val_int (this=0x8d81160) at item_cmpfunc.cc:1502
#7 0x08292aa3 in make_join_select (join=0x8d812c0, select=0x8d825f0, cond=0x8d81160) at sql_select.cc:5726
Problem is here:
double Item::val_real_from_decimal()
{
/* Note that fix_fields may not be called for Item_avg_field items */
double result;
my_decimal value_buff, *dec_val= val_decimal(&value_buff);
if (null_value)
return 0.0;
my_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
return result;
}
val_decimal() throws because time value is out of range (45:00:00 throws, 12:00:00 does not). This results in dec_val becoming NULL, but since null_value is not set, we then call my_decimal2double(...., dec_val==NULL, ...), which crashes like a drunk on a bike.
Potential fix:
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
if (get_date(<ime, TIME_FUZZY_DATE))
{
my_decimal_set_zero(decimal_value);
--> null_value= 1;
return 0;
}
return date2my_decimal(<ime, decimal_value);
}
This prevents further evaluation and throws a "Truncated incorrect datetime" warning to boot, which seems reasonable.
Alt approaches:
double Item::val_real_from_decimal()
if (null_value) => if (!dec_val)
This should return 0.0 with no warning.
OR
my_decimal2double(E_DEC_FATAL_ERROR, &value_buff, &result);
value_buff is always set to allocated memory, and Item::val_decimal_from_date() called my_decimal_set_zero() on that buffer. Be a total waste of time of course to convert a value we already know is 0 / invalid.
[5 Oct 2007 10:09]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/34954 ChangeSet@1.2526, 2007-10-05 12:08:38+02:00, tnurnberg@sin.intern.azundris.com +3 -0 Bug #31253: crash comparing datetime to double convert(<invalid time>, datetime) in WHERE caused crash as function returned (void*)NULL, but did not flag SQL NULL. It does now.
[6 Oct 2007 1:01]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/35025 ChangeSet@1.2568, 2007-10-06 03:01:30+02:00, tnurnberg@sin.intern.azundris.com +1 -0 Bug #31253: crash comparing datetime to double after-merge fixies
[6 Oct 2007 5:13]
Tatiana Azundris Nuernberg
pushed to 5.0.52, 5.1.23 maint
[18 Oct 2007 21:34]
Bugs System
Pushed into 5.1.23-beta
[18 Oct 2007 21:37]
Bugs System
Pushed into 5.0.52
[24 Oct 2007 19:39]
Paul DuBois
Noted in 5.0.52, 5.1.23 changelogs. CONVERT(val, DATETIME) would fail on invalid input, but processing was not aborted for the WHERE clause, leading to a server crash.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.059 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.