@@ -73,6 +73,14 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result);
7373struct tm * localtime_r (const time_t * timep , struct tm * result );
7474#endif
7575
76+ #ifndef CRON_TEST_MALLOC
77+ #define cronFree (x ) free(x);
78+ #define cronMalloc (x ) malloc(x);
79+ #else
80+ void * cronMalloc (size_t n );
81+ void cronFree (void * p );
82+ #endif
83+
7684/* Defining 'cron_mktime' to use use UTC (default) or local time */
7785#ifndef CRON_USE_LOCAL_TIME
7886
@@ -100,15 +108,6 @@ time_t cron_mktime(struct tm* tm) {
100108}
101109#endif /* _WIN32 */
102110
103-
104- #ifndef CRON_TEST_MALLOC
105- #define cronFree (x ) free(x);
106- #define cronMalloc (x ) malloc(x);
107- #else
108- void * cronMalloc (size_t n );
109- void cronFree (void * p );
110- #endif
111-
112111struct tm * cron_time (time_t * date , struct tm * out ) {
113112#ifdef __MINGW32__
114113 (void )(out ); /* To avoid unused warning */
@@ -585,6 +584,7 @@ static char** split_str(const char* str, char del, size_t* len_out) {
585584 memset (buf , 0 , stlen + 1 );
586585 res = (char * * ) cronMalloc (len * sizeof (char * ));
587586 if (!res ) goto return_error ;
587+ memset (res , 0 , len * sizeof (char * ));
588588
589589 for (i = 0 ; i < stlen ; i ++ ) {
590590 if (del == str [i ]) {
@@ -682,8 +682,8 @@ static unsigned int* get_range(char* field, unsigned int min, unsigned int max,
682682 res [1 ] = val ;
683683 } else {
684684 parts = split_str (field , '-' , & len );
685- if (0 == len || len > 2 ) {
686- * error = "Specified range has more than two fields" ;
685+ if (2 != len ) {
686+ * error = "Specified range requires two fields" ;
687687 goto return_error ;
688688 }
689689 int err = 0 ;
@@ -706,6 +706,10 @@ static unsigned int* get_range(char* field, unsigned int min, unsigned int max,
706706 * error = "Specified range is less than minimum" ;
707707 goto return_error ;
708708 }
709+ if (res [0 ] > res [1 ]) {
710+ * error = "Specified range start exceeds range end" ;
711+ goto return_error ;
712+ }
709713
710714 free_splitted (parts , len );
711715 * error = NULL ;
@@ -754,8 +758,8 @@ void set_number_hits(const char* value, uint8_t* target, unsigned int min, unsig
754758 } else {
755759 size_t len2 = 0 ;
756760 char * * split = split_str (fields [i ], '/' , & len2 );
757- if (0 == len2 || len2 > 2 ) {
758- * error = "Incrementer has more than two fields" ;
761+ if (2 != len2 ) {
762+ * error = "Incrementer must have two fields" ;
759763 free_splitted (split , len2 );
760764 goto return_result ;
761765 }
@@ -778,6 +782,12 @@ void set_number_hits(const char* value, uint8_t* target, unsigned int min, unsig
778782 free_splitted (split , len2 );
779783 goto return_result ;
780784 }
785+ if (0 == delta ) {
786+ * error = "Incrementer may not be zero" ;
787+ cronFree (range );
788+ free_splitted (split , len2 );
789+ goto return_result ;
790+ }
781791 for (i1 = range [0 ]; i1 <= range [1 ]; i1 += delta ) {
782792 cron_set_bit (target , i1 );
783793 }
@@ -826,12 +836,10 @@ static void set_days(char* field, uint8_t* targ, int max, const char** error) {
826836
827837static void set_days_of_month (char * field , uint8_t * targ , const char * * error ) {
828838 /* Days of month start with 1 (in Cron and Calendar) so add one */
829- set_days (field , targ , CRON_MAX_DAYS_OF_MONTH , error );
830- /* ... and remove it from the front */
831- if (targ ) {
832- cron_del_bit (targ , 0 );
839+ if (1 == strlen (field ) && '?' == field [0 ]) {
840+ field [0 ] = '*' ;
833841 }
834-
842+ set_number_hits ( field , targ , 1 , CRON_MAX_DAYS_OF_MONTH , error );
835843}
836844
837845void cron_parse_expr (const char * expression , cron_expr * target , const char * * error ) {
0 commit comments