msvcrt: Call invalid parameter handler in strftime.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2019-11-13 22:07:57 +01:00 committed by Alexandre Julliard
parent 7b60dcbefa
commit d0277873ea
1 changed files with 12 additions and 9 deletions

View File

@ -1116,7 +1116,8 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
if(MSVCRT__isleadbyte_l((unsigned char)*format, loc)) {
str[ret++] = *(format++);
if(ret == max) continue;
if(!str[ret]) goto einval_error;
if(!MSVCRT_CHECK_PMT(str[ret]))
goto einval_error;
}
str[ret++] = *format;
continue;
@ -1130,7 +1131,7 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
alternate = FALSE;
}
if(!mstm)
if(!MSVCRT_CHECK_PMT(mstm))
goto einval_error;
switch(*format) {
@ -1151,13 +1152,13 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
return 0;
break;
case 'a':
if(mstm->tm_wday<0 || mstm->tm_wday>6)
if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
goto einval_error;
if(!strftime_str(str, &ret, max, time_data->str.names.short_wday[mstm->tm_wday]))
return 0;
break;
case 'A':
if(mstm->tm_wday<0 || mstm->tm_wday>6)
if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
goto einval_error;
if(!strftime_str(str, &ret, max, time_data->str.names.wday[mstm->tm_wday]))
return 0;
@ -1166,13 +1167,13 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
#if _MSVCR_VER>=140
case 'h':
#endif
if(mstm->tm_mon<0 || mstm->tm_mon>11)
if(!MSVCRT_CHECK_PMT(mstm->tm_mon>=0 && mstm->tm_mon<=11))
goto einval_error;
if(!strftime_str(str, &ret, max, time_data->str.names.short_mon[mstm->tm_mon]))
return 0;
break;
case 'B':
if(mstm->tm_mon<0 || mstm->tm_mon>11)
if(!MSVCRT_CHECK_PMT(mstm->tm_mon>=0 && mstm->tm_mon<=11))
goto einval_error;
if(!strftime_str(str, &ret, max, time_data->str.names.mon[mstm->tm_mon]))
return 0;
@ -1268,7 +1269,7 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
break;
#endif
case 'p':
if(mstm->tm_hour<0 || mstm->tm_hour>23)
if(!MSVCRT_CHECK_PMT(mstm->tm_hour>=0 && mstm->tm_hour<=23))
goto einval_error;
if(!strftime_str(str, &ret, max, mstm->tm_hour<12 ?
time_data->str.names.am : time_data->str.names.pm))
@ -1338,7 +1339,9 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
break;
case 'U':
case 'W':
if(mstm->tm_wday<0 || mstm->tm_wday>6 || mstm->tm_yday<0 || mstm->tm_yday>365)
if(!MSVCRT_CHECK_PMT(mstm->tm_wday>=0 && mstm->tm_wday<=6))
goto einval_error;
if(!MSVCRT_CHECK_PMT(mstm->tm_yday>=0 && mstm->tm_yday<=365))
goto einval_error;
if(*format == 'U')
tmp = mstm->tm_wday;
@ -1356,6 +1359,7 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
break;
default:
WARN("unknown format %c\n", *format);
MSVCRT_INVALID_PMT("unknown format", MSVCRT_EINVAL);
goto einval_error;
}
}
@ -1372,7 +1376,6 @@ static MSVCRT_size_t strftime_helper(char *str, MSVCRT_size_t max, const char *f
einval_error:
*str = 0;
*MSVCRT__errno() = MSVCRT_EINVAL;
return 0;
}