diff options
author | Christoph M. Becker <cmb@php.net> | 2016-07-29 01:12:12 +0200 |
---|---|---|
committer | Christoph M. Becker <cmb@php.net> | 2016-07-29 01:26:15 +0200 |
commit | 293dd3d7017e3df8f06898d3a7d1c00eb935ee0c (patch) | |
tree | 1a3f8fc4f656ef5d1550e5ea0432f6d286373335 /ext/calendar | |
parent | a952aac6a751b2ea9c015590a1c4597f86762bce (diff) | |
parent | f67ccd4a7b8fb4b9e55796e69b152e2a899ba3cd (diff) | |
download | php-git-293dd3d7017e3df8f06898d3a7d1c00eb935ee0c.tar.gz |
Merge branch 'PHP-5.6' into PHP-7.0
# Resolved conflicts:
# ext/calendar/calendar.c
Diffstat (limited to 'ext/calendar')
-rw-r--r-- | ext/calendar/calendar.c | 20 | ||||
-rw-r--r-- | ext/calendar/tests/bug71894.phpt | 32 |
2 files changed, 45 insertions, 7 deletions
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c index 2e0f53e561..40ae249cda 100644 --- a/ext/calendar/calendar.c +++ b/ext/calendar/calendar.c @@ -418,15 +418,21 @@ PHP_FUNCTION(cal_from_jd) add_assoc_long(return_value, "year", year); /* day of week */ - dow = DayOfWeek(jd); - add_assoc_long(return_value, "dow", dow); - add_assoc_string(return_value, "abbrevdayname", DayNameShort[dow]); - add_assoc_string(return_value, "dayname", DayNameLong[dow]); + if (cal != CAL_JEWISH || year > 0) { + dow = DayOfWeek(jd); + add_assoc_long(return_value, "dow", dow); + add_assoc_string(return_value, "abbrevdayname", DayNameShort[dow]); + add_assoc_string(return_value, "dayname", DayNameLong[dow]); + } else { + add_assoc_null(return_value, "dow"); + add_assoc_string(return_value, "abbrevdayname", ""); + add_assoc_string(return_value, "dayname", ""); + } /* month name */ if(cal == CAL_JEWISH) { /* special case for Jewish calendar */ - add_assoc_string(return_value, "abbrevmonth", JEWISH_MONTH_NAME(year)[month]); - add_assoc_string(return_value, "monthname", JEWISH_MONTH_NAME(year)[month]); + add_assoc_string(return_value, "abbrevmonth", (year > 0 ? JEWISH_MONTH_NAME(year)[month] : "")); + add_assoc_string(return_value, "monthname", (year > 0 ? JEWISH_MONTH_NAME(year)[month] : "")); } else { add_assoc_string(return_value, "abbrevmonth", calendar->month_name_short[month]); add_assoc_string(return_value, "monthname", calendar->month_name_long[month]); @@ -739,7 +745,7 @@ PHP_FUNCTION(jdmonthname) break; case CAL_MONTH_JEWISH: /* jewish month */ SdnToJewish(julday, &year, &month, &day); - monthname = JEWISH_MONTH_NAME(year)[month]; + monthname = (year > 0 ? JEWISH_MONTH_NAME(year)[month] : ""); break; case CAL_MONTH_FRENCH: /* french month */ SdnToFrench(julday, &year, &month, &day); diff --git a/ext/calendar/tests/bug71894.phpt b/ext/calendar/tests/bug71894.phpt new file mode 100644 index 0000000000..ea2d6004e7 --- /dev/null +++ b/ext/calendar/tests/bug71894.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #71894 (AddressSanitizer: global-buffer-overflow in zif_cal_from_jd) +--SKIPIF-- +<?php +if (!extension_loaded('calendar')) die('skip ext/calendar required'); +?> +--FILE-- +<?php +var_dump(cal_from_jd(347997, CAL_JEWISH)); +var_dump(jdmonthname(347997,CAL_MONTH_JEWISH));?> +--EXPECT-- +array(9) { + ["date"]=> + string(5) "0/0/0" + ["month"]=> + int(0) + ["day"]=> + int(0) + ["year"]=> + int(0) + ["dow"]=> + NULL + ["abbrevdayname"]=> + string(0) "" + ["dayname"]=> + string(0) "" + ["abbrevmonth"]=> + string(0) "" + ["monthname"]=> + string(0) "" +} +string(0) "" |