uTasker / uTasker-Kinetis

uTasker V1.4.11 based open source version for Kinetis and STM32 parts
60 stars 35 forks source link

fnConvertTimeSeconds crashes when called with empty struct #9

Closed lz80becker closed 5 years ago

lz80becker commented 5 years ago

Hi,

recently I had some weird crashes when using an external RTC chip on my hardware. The cause of the crash is in the function "fnConvertTimeSeconds" in time_keeper.c because there is no check if the fields of the struct are empty and they get decremented by 1.

ulUnit = (ptr_rtc_setup->ucDayOfMonth - 1); // passed days in month ucNewWeekDay = fnIncDayOfWeek(ucNewWeekDay, (unsigned char)ulUnit); while (ulUnit--) { ulPassedSeconds += (60 * 60 * 24); // count passed days in present month }

The while loop called starting with a value of 0xFFFFFFFE will take too much time and cause the watchdog to trigger a reset.

uTasker commented 5 years ago

Hi Many thanks for reporting this issue. Rather than add complete checking of input ranges in the case of a non-initialised external RTC (with zero struct or other potentially random values) I have made it safe by doing: ulUnit = (unsigned char)(ptr_rtc_setup->ucMonthOfYear- 1); and ulUnit = (unsigned char)(ptr_rtc_setup->ucDayOfMonth - 1); at 2 different locations where they occur.

This will cause a zeroed struct to give a small ulUnit of 0xff rather than 0xffffffff so that loops will not be long. The result of course doesn't make great sense but one would then set the correct date/time to start/continue normally anyway. The risk of invalid input causing a watchdog reset will then be excluded. Regards Mark