wininet: Fix behaviour of InternetTimeFromSystemTimeA/W when a buffer that is too small is passed in.

This commit is contained in:
Rob Shearman 2008-10-02 11:38:38 +01:00 committed by Alexandre Julliard
parent ef0e3792bb
commit fa066c74e3
2 changed files with 13 additions and 6 deletions

View File

@ -2478,6 +2478,12 @@ BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, L
TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
@ -2495,11 +2501,15 @@ BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, L
TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
if (!time || !string) return FALSE;
if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
if (!time || !string || format != INTERNET_RFC1123_FORMAT)
return FALSE;
if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
sprintfW( string, date,
WININET_wkday[time->wDayOfWeek],
time->wDay,

View File

@ -800,12 +800,10 @@ static void InternetTimeFromSystemTimeA_test(void)
SetLastError(0xdeadbeef);
ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
error = GetLastError();
todo_wine {
ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
ok( error == ERROR_INSUFFICIENT_BUFFER,
"InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
error );
}
}
static void InternetTimeFromSystemTimeW_test(void)
@ -827,7 +825,6 @@ static void InternetTimeFromSystemTimeW_test(void)
ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
error = GetLastError();
ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
todo_wine
ok( error == ERROR_INSUFFICIENT_BUFFER,
"InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
error );