Bug #2545 mysqld 4.1.1 core dumps when GREATEST() returns a NULL value
Submitted: 28 Jan 2004 9:21 Modified: 10 Mar 2004 12:17
Reporter: Jani Tolonen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1 OS:Any (All)
Assigned to: Jani Tolonen CPU Architecture:Any

[28 Jan 2004 9:21] Jani Tolonen
Description:
mysqld core dumps if LEAST() or GREATEST() should return a NULL.

How to repeat:
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (d varchar(6), k int);
INSERT INTO t1 VALUES (NULL, 2);
SELECT GREATEST(d,d) FROM t1 WHERE k=2;

Suggested fix:
*** sql/item_func.cc.org        2004-01-28 18:42:26.000000000 +0200
--- sql/item_func.cc    2004-01-28 18:42:32.000000000 +0200
***************
*** 1068,1073 ****
--- 1068,1075 ----
        }
        }
      }
+     if (!res)  // If NULL
+       return 0;
      res->set_charset(collation.collation);
      return res;
    }