Commit 69d8bfe2 authored by unknown's avatar unknown
Browse files

Fix for bug #23653: Crash if last_day('0000-00-00')

As get_arg0_date() in the Item_func_last_day::get_date() returns 
0000-00-00 date sometimes, we have to check ltime->month for 0 after the call.


mysql-test/r/func_time.result:
  Fix for bug #23653: Crash if last_day('0000-00-00')
    - test result.
mysql-test/t/func_time.test:
  Fix for bug #23653: Crash if last_day('0000-00-00')
    - test case.
sql/item_timefunc.cc:
  Fix for bug #23653: Crash if last_day('0000-00-00')
    - return error if month is 0.
parent 870b2e0a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -815,4 +815,7 @@ union
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H);
H
5
select last_day('0000-00-00');
last_day('0000-00-00')
NULL
End of 4.1 tests
+6 −0
Original line number Diff line number Diff line
@@ -446,4 +446,10 @@ union
union
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H);

#
# Bug #23653: crash if last_day('0000-00-00')
#

select last_day('0000-00-00');

--echo End of 4.1 tests
+2 −1
Original line number Diff line number Diff line
@@ -3058,7 +3058,8 @@ String *Item_func_str_to_date::val_str(String *str)

bool Item_func_last_day::get_date(TIME *ltime, uint fuzzy_date)
{
  if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE))
  if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE) ||
      (ltime->month == 0))
    return 1;
  uint month_idx= ltime->month-1;
  ltime->day= days_in_month[month_idx];