php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52808 Segfault when specifying interval as two dates
Submitted: 2010-09-09 23:45 UTC Modified: 2011-01-30 09:55 UTC
From: joey@php.net Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3, trunk OS: Debian stable
Private report: No CVE-ID: None
 [2010-09-09 23:45 UTC] joey@php.net
Description:
------------
Creating an interval with a "negative duration" (i.e., "start" date precedes "end" date) creates what appears to be a valid DateInterval object, but any attempt to work with the object results in a segfault.

Test script:
---------------
<?php $a = new DateInterval("2008-05-11T15:30:00Z/2007-03-01T13:00:00Z"); var_dump($a); ?>

Expected result:
----------------
At a minimum, "Not crashing". Ideally, a DateInterval object with a negative duration, but I don't know of ISO-8601 allows those.

Actual result:
--------------

(gdb) r -r '$a = new DateInterval("2008-05-11T15:30:00Z/2007-03-01T13:00:00Z"); var_dump($a);'

Program received signal SIGSEGV, Segmentation fault.
0x0000000000420faf in date_object_get_properties_interval (object=<value optimized out>) at /home/joey/src/php/trunk/ext/date/php_date.c:2242
2242            PHP_DATE_INTERVAL_ADD_PROPERTY("y", y);

"bt full" output available at http://codepad.org/on7ZS6Qd

Patches

bug52808.patch (last revision 2010-09-10 22:18 UTC by sriram dot natarajan at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-09 23:46 UTC] joey@php.net
-Assigned To: +Assigned To: derick
 [2010-09-11 00:22 UTC] srinatar@php.net
looks like my comment was lost in the previous post while uploading my patch.

i was wondering, if dateinterval constructor accepts a general format of date string. looking at the code it does not seem to be as well. 

manual suggests that you need to provide the input date in format ISO8601 format. 

for example year 10th may, 2008 would be given as 
$a = new DateInterval("P2008Y5M11DT15H30M00S");

I haven't used this API much.So, I could be wrong.
 [2010-12-05 17:01 UTC] felipe@php.net
-PHP Version: trunk-SVN-2010-09-09 (SVN) +PHP Version: 5.3, trunk
 [2011-01-30 09:42 UTC] stas@php.net
-Summary: Negative intervals segfault +Summary: Segfault when specifying interval as two dates
 [2011-01-30 09:54 UTC] stas@php.net
Automatic comment from SVN on behalf of stas
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=307846
Log: Fix bug #52808 (Segfault when specifying interval as two dates)
 [2011-01-30 09:55 UTC] stas@php.net
-Status: Assigned +Status: Closed
 [2011-01-30 09:55 UTC] stas@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC