* Update MSVCRT_CHECK_PMT and co.
* Update the use of MSVCRT_INVALID_PMT throughout our code.
* Fix the return of _ltoa_s() in some case. Fixes a couple msvcrt:string tests.
CORE-8080

svn path=/trunk/; revision=63223
This commit is contained in:
Amine Khaldi 2014-05-10 20:38:26 +00:00
parent be359827c5
commit 8ce24812f8
10 changed files with 24 additions and 49 deletions

View file

@ -11,10 +11,12 @@ void _invalid_parameter(
uintptr_t pReserved);
#ifndef _LIBCNT_
#define MSVCRT_INVALID_PMT(x) _invalid_parameter(NULL, NULL, NULL, 0, 0)
#define MSVCRT_CHECK_PMT(x) ((x) || (MSVCRT_INVALID_PMT(0),0))
#define MSVCRT_INVALID_PMT(x,err) (*_errno() = (err), _invalid_parameter(NULL, NULL, NULL, 0, 0))
#define MSVCRT_CHECK_PMT_ERR(x,err) ((x) || (MSVCRT_INVALID_PMT( 0, (err) ), 0))
#define MSVCRT_CHECK_PMT(x) MSVCRT_CHECK_PMT_ERR((x), EINVAL)
#else
/* disable secure crt parameter checks */
#define MSVCRT_CHECK_PMT
#define MSVCRT_INVALID_PMT
#define MSVCRT_INVALID_PMT(x,err)
#define MSVCRT_CHECK_PMT_ERR(x,err)
#define MSVCRT_CHECK_PMT(x) (x)
#endif

View file

@ -104,7 +104,7 @@ _sxprintf(
if (count != _TRUNCATE)
{
/* We can't, invoke invalid parameter handler */
MSVCRT_INVALID_PMT("Buffer is too small");
MSVCRT_INVALID_PMT("Buffer is too small", ERANGE);
/* If we came back, set the buffer to an empty string */
*buffer = 0;

View file

@ -1553,8 +1553,7 @@ int CDECL _sopen_s( int *fd, const char *path, int oflags, int shflags, int pmod
if (!fd)
{
MSVCRT_INVALID_PMT("null out fd pointer");
*_errno() = EINVAL;
MSVCRT_INVALID_PMT("null out fd pointer", EINVAL);
return EINVAL;
}
@ -1672,8 +1671,7 @@ int CDECL _wsopen_s( int *fd, const wchar_t* path, int oflags, int shflags, int
if (!fd)
{
MSVCRT_INVALID_PMT("null out fd pointer");
*_errno() = EINVAL;
MSVCRT_INVALID_PMT("null out fd pointer", EINVAL);
return EINVAL;
}

View file

@ -109,8 +109,7 @@ int _tsearchenv_s(const _TCHAR* file, const _TCHAR* env, _TCHAR *buf, size_t cou
{
if (_tcslen(curPath) + 1 > count)
{
MSVCRT_INVALID_PMT("buf[count] is too small");
*_errno() = ERANGE;
MSVCRT_INVALID_PMT("buf[count] is too small", ERANGE);
return ERANGE;
}
_tcscpy(buf, curPath);

View file

@ -113,10 +113,7 @@ int CDECL _i64toa_s(__int64 value, char *str, size_t size, int radix)
*p++ = *pos--;
str[0] = '\0';
MSVCRT_INVALID_PMT("str[size] is too small");
#ifndef _LIBCNT_
*_errno() = ERANGE;
#endif
MSVCRT_INVALID_PMT("str[size] is too small", ERANGE);
return ERANGE;
}
@ -182,10 +179,7 @@ int CDECL _ui64toa_s(unsigned __int64 value, char *str,
}while(value != 0);
if((unsigned)(buffer-pos+65) > size) {
MSVCRT_INVALID_PMT("str[size] is too small");
#ifndef _LIBCNT_
*_errno() = EINVAL;
#endif
MSVCRT_INVALID_PMT("str[size] is too small", EINVAL);
return EINVAL;
}
@ -322,10 +316,7 @@ int CDECL _ltoa_s(long value, char *str, size_t size, int radix)
*p++ = *pos--;
str[0] = '\0';
MSVCRT_INVALID_PMT("str[size] is too small");
#ifndef _LIBCNT_
*_errno() = EINVAL;
#endif
MSVCRT_INVALID_PMT("str[size] is too small", ERANGE);
return ERANGE;
}

View file

@ -123,11 +123,8 @@ _i64tow_s(__int64 value, wchar_t *str, size_t size, int radix)
for (pos = buffer + 63, i = 0; i < size; i++)
*p++ = *pos--;
MSVCRT_INVALID_PMT("str[size] is too small");
MSVCRT_INVALID_PMT("str[size] is too small", ERANGE);
str[0] = '\0';
#ifndef _LIBCNT_
*_errno() = ERANGE;
#endif
return ERANGE;
}
@ -195,10 +192,7 @@ _ui64tow_s( unsigned __int64 value, wchar_t *str,
} while (value != 0);
if((size_t)(buffer-pos+65) > size) {
MSVCRT_INVALID_PMT("str[size] is too small");
#ifndef _LIBCNT_
*_errno() = EINVAL;
#endif
MSVCRT_INVALID_PMT("str[size] is too small", EINVAL);
return EINVAL;
}
@ -338,11 +332,8 @@ _ltow_s(long value, wchar_t *str, size_t size, int radix)
for (pos = buffer + 31, i = 0; i < size; i++)
*p++ = *pos--;
MSVCRT_INVALID_PMT("str[size] is too small");
MSVCRT_INVALID_PMT("str[size] is too small", ERANGE);
str[0] = '\0';
#ifndef _LIBCNT_
*_errno() = ERANGE;
#endif
return ERANGE;
}

View file

@ -204,8 +204,7 @@ int CDECL __wcserror_s(wchar_t* buffer, size_t nc, const wchar_t* str)
if (str && *str) len += lstrlenW(str) + 2 /* ': ' */;
if (len > nc)
{
MSVCRT_INVALID_PMT("buffer[nc] is too small");
_set_errno(ERANGE);
MSVCRT_INVALID_PMT("buffer[nc] is too small", ERANGE);
return ERANGE;
}
if (str && *str)

View file

@ -432,7 +432,7 @@ INT CDECL wcsncat_s(wchar_t *dst, size_t elem,
}
if (dststart == elem)
{
MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n");
MSVCRT_INVALID_PMT("dst[elem] is not NULL terminated\n", EINVAL);
return EINVAL;
}
@ -453,7 +453,7 @@ INT CDECL wcsncat_s(wchar_t *dst, size_t elem,
dst[dststart+srclen] = '\0';
return ret;
}
MSVCRT_INVALID_PMT("dst[elem] is too small");
MSVCRT_INVALID_PMT("dst[elem] is too small", ERANGE);
dst[0] = '\0';
return ERANGE;
}

View file

@ -126,15 +126,13 @@ _gmtime64_s(
__time64_t time = *ptime;
if (!ptm)
{
_set_errno(ERROR_BAD_COMMAND);
MSVCRT_INVALID_PMT("ptm == NULL");
MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND);
return ERROR_BAD_COMMAND;
}
if (!ptime)
{
_set_errno(ERROR_BAD_COMMAND);
MSVCRT_INVALID_PMT("ptime == NULL");
MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
return ERROR_BAD_COMMAND;
}
@ -167,15 +165,13 @@ _gmtime32_s(
__time64_t time = *ptime;
if (!ptm)
{
_set_errno(ERROR_BAD_COMMAND);
MSVCRT_INVALID_PMT("ptm == NULL");
MSVCRT_INVALID_PMT("ptm == NULL", ERROR_BAD_COMMAND);
return ERROR_BAD_COMMAND;
}
if (!ptime)
{
_set_errno(ERROR_BAD_COMMAND);
MSVCRT_INVALID_PMT("ptime == NULL");
MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
return ERROR_BAD_COMMAND;
}

View file

@ -603,8 +603,7 @@ int CDECL strncpy_s(char *dest, size_t numberOfElements,
return 0;
}
MSVCRT_INVALID_PMT("dest[numberOfElements] is too small");
MSVCRT_INVALID_PMT("dest[numberOfElements] is too small", EINVAL);
dest[0] = '\0';
*_errno() = EINVAL;
return EINVAL;
}