fix: Add input validation to Schedule_Recalculate_PV and Schedule_Timer functions to prevent segmentation fault occurring in Schedule_Recalculate_PV() during application startup (#1259)
This commit is contained in:
@@ -1043,6 +1043,10 @@ void Schedule_Recalculate_PV(
|
||||
{
|
||||
int i, current, diff;
|
||||
BACNET_TIME *tmptime;
|
||||
|
||||
if (!desc || !time || (wday < 1) || (wday > 7)) {
|
||||
return;
|
||||
}
|
||||
desc->Present_Value.tag = BACNET_APPLICATION_TAG_NULL;
|
||||
|
||||
/* for future development, here should be the loop for Exception Schedule */
|
||||
@@ -1088,11 +1092,13 @@ void Schedule_Recalculate_PV(
|
||||
*/
|
||||
void Schedule_Timer(uint32_t object_instance, uint16_t milliseconds)
|
||||
{
|
||||
SCHEDULE_DESCR *pObject;
|
||||
BACNET_DATE_TIME bdatetime;
|
||||
|
||||
UNUSED(milliseconds);
|
||||
|
||||
Device_getCurrentDateTime(&bdatetime);
|
||||
|
||||
Schedule_Recalculate_PV(
|
||||
Schedule_Object(object_instance), bdatetime.date.wday, &bdatetime.time);
|
||||
pObject = Schedule_Object(object_instance);
|
||||
if (pObject) {
|
||||
Device_getCurrentDateTime(&bdatetime);
|
||||
Schedule_Recalculate_PV(pObject, bdatetime.date.wday, &bdatetime.time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,13 @@ static void testSchedule(void)
|
||||
skip_fail_property_list);
|
||||
Schedule_Recalculate_PV(
|
||||
Schedule_Object(object_instance), BACNET_WEEKDAY_SUNDAY, &time_of_day);
|
||||
/* targeted tests for NULL pointer and invalid day of week */
|
||||
Schedule_Recalculate_PV(NULL, BACNET_WEEKDAY_SUNDAY, &time_of_day);
|
||||
Schedule_Recalculate_PV(Schedule_Object(object_instance), 0, &time_of_day);
|
||||
Schedule_Recalculate_PV(Schedule_Object(object_instance), 8, &time_of_day);
|
||||
Schedule_Recalculate_PV(
|
||||
Schedule_Object(object_instance), BACNET_WEEKDAY_SUNDAY, NULL);
|
||||
Schedule_Timer(BACNET_MAX_INSTANCE, 0);
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
|
||||
Reference in New Issue
Block a user