MyBB Community Forums

Full Version: [F] Announcement date bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Description:
If you add an announcement both from the admincp and the modcp and select a month before November and save that. It will automatically change back to January (1).

Reproducible: always

Steps to reproduce:
1) Go to AdminCP > Forums & Posts > Announcements and click Add Announcement
2) Choose any month from January until October.
3) Fill in the other required fields
4) Save the announcement
5) Click on the edit-link for the announcement you just created
6) The month is changed to January.

I think the problem is this piece of code:
if($mybb->input['starttime_month'] > 12 ||
(int)$mybb->input['starttime_month'] < 1 ||
!is_int($mybb->input['starttime_month']))
{
	$mybb->input['starttime_month'] = 1;
}
This is from /admin/modules/forum/announcements.php but I think there is also similar code in modcp.php. is_int() will always return false on a POST/GET variable because it's always text.
var_dump( is_int( 4 ) ); // bool(true)
var_dump( is_int( '4' ) ); // bool(false)
var_dump( is_int( '04' ) ); // bool(false)
So the if statement above will always return true:
$mybb->input['starttime_month'] > 12 === '04' > 12 === false
(int)$mybb->input['starttime_month'] < 1 === '04' < 1 === false
!is_int($mybb->input['starttime_month']) === !is_int('04') === true
false || false || true === true

I'm sorry if this was already reported but I couldn't find any thread of this.

[EDIT]
Oh yeah, I'm using PHP 5.2.6.
Try replacing it with this:

$months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
			
			if(!in_array($mybb->input['starttime_month'], $months))
			{
				$mybb->input['starttime_month'] = 1;
			}

We can't use intval because it produces weird results with a 0 appended to the number, so instead we'll run it through a test case
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.
(2008-06-28, 10:12 PM)Tikitiki Wrote: [ -> ]We can't use intval because it produces weird results with a 0 appended to the number, so instead we'll run it through a test case

I think this only affects numbers with an appending zero:
var_dump( intval( '08' ) ); // int(8)
var_dump( intval( 08 ) ); // int(0)

The function gmmktime() will also cast the month to an integer so I don't think it would make any difference.

Maybe this would be a better idea for the fix:
$months = array(1=>'01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
$month = array_search( $mybb->input['starttime_month'] , $months );
$mybb->input['starttime_month'] = $month !== false ? $month : 1;
That way you always have a real integer to pass with the gmmktime() function.
(2008-06-29, 01:39 PM)Aries-Belgium Wrote: [ -> ]Maybe this would be a better idea for the fix:
$months = array(1=>'01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
$month = array_search( $mybb->input['starttime_month'] , $months );
$mybb->input['starttime_month'] = $month !== false ? $month : 1;
That way you always have a real integer to pass with the gmmktime() function.

That's pretty much exactly what I did and what I meant by "test cases"