diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index fc872285acb7347918da2e953c21a43c0912dcb5..02f3d2f72732584b6de046665e651fca4520b6c8 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -626,3 +626,7 @@ last_day('2005-01-00')
 NULL
 Warnings:
 Warning	1292	Truncated incorrect datetime value: '2005-01-00'
+select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
+monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));
+monthname(str_to_date(null, '%m'))	monthname(str_to_date(null, '%m'))	monthname(str_to_date(1, '%m'))	monthname(str_to_date(0, '%m'))
+NULL	NULL	January	NULL
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index 68a33afd85ca799b78dc65c0ff13aef1f5af9fde..01e4e47d318f360ea460f3329b97245863374f9e 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -315,4 +315,11 @@ select last_day('2005-00-00');
 select last_day('2005-00-01');
 select last_day('2005-01-00');
 
+#
+# Bug #18501: monthname and NULLs
+#
+
+select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
+       monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));
+
 # End of 4.1 tests
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index f3d6858755c2d1ebfc375f38c184951ea2800842..ffd8c79dca8bc082c30eecd1efb988bf1cbc79df 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -905,9 +905,9 @@ String* Item_func_monthname::val_str(String* str)
 {
   DBUG_ASSERT(fixed == 1);
   const char *month_name;
-  uint   month=(uint) Item_func_month::val_int();
+  uint   month= (uint) val_int();
 
-  if (!month)					// This is also true for NULL
+  if (null_value || !month)
   {
     null_value=1;
     return (String*) 0;