mongoose-os-libs / cron

Other
6 stars 8 forks source link

Cron expressions make core dump #3

Open iliapenev opened 3 years ago

iliapenev commented 3 years ago

Setting cron expressions like 0 4 0 * * MON-SUN or 0 4 0 * 4-2 * leads to core dump and device crash.

When 0 4 0 * * MON-SUN or 0 4 0 * *FRI-WED period is given while loop in find_next_day() https://github.com/mongoose-os-libs/cron/blob/master/src/ccronexpr.c#L354 leads to crash. All values are 0 in days_of_week = set_days(days_replaced, 8, error); this should be error. https://github.com/mongoose-os-libs/cron/blob/master/src/ccronexpr.c#L874 When device reboots, core dump appears again, start point appears to be when mgos_cron_get_next_invocation() is called. Boot error loop happens.

With others expression like 0 4 0 * 4-2 * after core dump and reboot, device does not have boot error loop.

SUN (0) is first day of week in crontab, but in some implementations SUN is also 7. There is handler for /* Sunday can be represented as 0 or 7 */ but seems that MON-SUN is not valid https://github.com/mongoose-os-libs/cron/blob/master/src/ccronexpr.c#L878

Tested on ESP32 platform.

[Jan 13 13:37:41.527] Guru Meditation Error: Core  1 panic'ed (Unhandled debug exception). 
[Jan 13 13:37:41.532] Debug exception reason: Stack canary watchpoint triggered ( ) 
[Jan 13 13:37:41.538] Core  1 register dump:
[Jan 13 13:37:41.538] PC      : 0x4008be57  PS      : 0x00060c36  A0      : 0x80082ebd  A1      : 0x3ffb5450  
[Jan 13 13:37:41.546] A2      : 0x3ffbe7ec  A3      : 0x00000000  A4      : 0xffffffff  A5      : 0x00000000  
[Jan 13 13:37:41.554] A6      : 0x00000001  A7      : 0x3ffb55f0  A8      : 0x8010d6c1  A9      : 0x3ffb5580  
[Jan 13 13:37:41.562] A10     : 0x3ffc481c  A11     : 0x3ffb7080  A12     : 0x00000046  A13     : 0x3ffc5acc  
[Jan 13 13:37:41.571] A14     : 0x3ffc5aec  A15     : 0x3ffb5590  SAR     : 0x0000001f  EXCCAUSE: 0x00000001  
[Jan 13 13:37:41.579] EXCVADDR: 0x00000000  LBEG    : 0x401c2814  LEND    : 0x401c281b  LCOUNT  : 0x00000000  
[Jan 13 13:37:41.584] 
[Jan 13 13:37:41.584] Backtrace:0x4008be54 0x40082eba 0x40082f75 0x4000be21 0x40001a0a 0x4005a7a1 0x4010d4e1 0x4010d5d0 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d6ed 0x4010d6ad 0x4010d6be 0x4010d6ad 0x4010d98e 0x4010dde6 0x4010e10c 0x4010e28b 0x4010f276 0x4010f3af 0x401c2841 0x4010f19a 0x4010f1bb 0x4010f7cd 0x4010fab6 0x400d9ca4 0x400d367b 0x400dabcf 0x400829dc
[Jan 13 13:37:41.676] 
[Jan 13 13:37:41.676] 
[Jan 13 13:37:41.676] ELF file SHA256: b06ac7f0f9a281d0
[Jan 13 13:37:41.678] 
[Jan 13 13:37:41.678] 
[Jan 13 13:37:41.678] --- BEGIN CORE DUMP ---
[Jan 13 13:37:41.681] mos: catching core dump
[Jan 13 13:37:41.692] mos: core dump aborted
[Jan 13 13:37:41.692] 
[Jan 13 13:37:41.692] Core  1 register dump:
[Jan 13 13:37:41.695] PC      : 0x4012c483  PS      : 0x00060535  A0      : 0x801378f1  A1      : 0x3ffb4df0  
[Jan 13 13:37:41.703] A2      : 0x3ffb5360  A3      : 0x3ffb5100  A4      : 0x3f402d71  A5      : 0x3ffb5260  
[Jan 13 13:37:41.711] A6      : 0x3ffb5240  A7      : 0x00000004  A8      : 0x8012c483  A9      : 0x3ffb4dd0  
[Jan 13 13:37:41.717] A10     : 0x4008bf47  A11     : 0x00060f23  A12     : 0x00060f25  A13     : 0x3ffb38b9  
[Jan 13 13:37:41.725] A14     : 0x4010d4fa  A15     : 0x0000003c  SAR     : 0x0000000a  EXCCAUSE: 0x00000009  
[Jan 13 13:37:41.734] EXCVADDR: 0x4008bf47  LBEG    : 0x400d31b0  LEND    : 0x400d31c1  LCOUNT  : 0x00000005  
[Jan 13 13:37:41.742] 
[Jan 13 13:37:41.742] Backtrace:0x4012c480 0x401378ee 0x4013792a 0x400d30a2 0x400d316f 0x40081723 0x4008882d 0x40088971 0x40088cf5 0x40085815 0x00040022 |<-CORRUPTED
[Jan 13 13:37:41.753] 
[Jan 13 13:37:41.753] 
[Jan 13 13:37:41.753] ELF file SHA256: b06ac7f0f9a281d0
[Jan 13 13:37:41.758] 
[Jan 13 13:37:41.758] Re-entered core dump! Exception happened during core dump!
[Jan 13 13:37:41.764] Rebooting...
[Jan 13 13:37:41.764] ets Jun  8 2016 00:22:57
[Jan 13 13:37:41.767] 
[Jan 13 13:37:41.767] rst:0xc (SW_CPU_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT)
rojer commented 3 years ago

i agree it shouldn't crash, but taht said - 'mon-sun' is basically '*'

rojer commented 3 years ago

i see that you have investigated the issue, would you mind putting up a PR to fix it? it's been a while since i've looked at cron internals.