Commit 17f486ba authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Added support for secure functions to scanf helper functions.

parent 8a69a936
......@@ -24,6 +24,7 @@
*/
#include <stdarg.h>
#include <limits.h>
#include "windef.h"
#include "winbase.h"
......@@ -61,30 +62,35 @@ static int wchar2digit(MSVCRT_wchar_t c, int base) {
#undef WIDE_SCANF
#undef CONSOLE
#undef STRING
#undef SECURE
#include "scanf.h"
/* vfwscanf_l */
#define WIDE_SCANF 1
#undef CONSOLE
#undef STRING
#undef SECURE
#include "scanf.h"
/* vsscanf_l */
#undef WIDE_SCANF
#undef CONSOLE
#define STRING 1
#undef SECURE
#include "scanf.h"
/* vswscanf_l */
#define WIDE_SCANF 1
#undef CONSOLE
#define STRING 1
#undef SECURE
#include "scanf.h"
/* vcscanf_l */
#undef WIDE_SCANF
#define CONSOLE 1
#undef STRING
#undef SECURE
#include "scanf.h"
......
......@@ -48,7 +48,11 @@
#ifdef CONSOLE
#define _GETC_(file) (consumed++, _getch())
#define _UNGETC_(nch, file) do { _ungetch(nch); consumed--; } while(0)
#ifdef SECURE
#define _FUNCTION_ static int MSVCRT_vcscanf_s_l(const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#else /* SECURE */
#define _FUNCTION_ static int MSVCRT_vcscanf_l(const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#endif /* SECURE */
#else
#ifdef STRING
#undef _EOF_
......@@ -56,19 +60,35 @@
#define _GETC_(file) (consumed++, *file++)
#define _UNGETC_(nch, file) do { file--; consumed--; } while(0)
#ifdef WIDE_SCANF
#ifdef SECURE
#define _FUNCTION_ static int MSVCRT_vswscanf_s_l(const MSVCRT_wchar_t *file, const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list ap)
#else /* SECURE */
#define _FUNCTION_ static int MSVCRT_vswscanf_l(const MSVCRT_wchar_t *file, const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list ap)
#endif /* SECURE */
#else /* WIDE_SCANF */
#ifdef SECURE
#define _FUNCTION_ static int MSVCRT_vsscanf_s_l(const char *file, const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#else /* SECURE */
#define _FUNCTION_ static int MSVCRT_vsscanf_l(const char *file, const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#endif /* SECURE */
#endif /* WIDE_SCANF */
#else /* STRING */
#ifdef WIDE_SCANF
#define _GETC_(file) (consumed++, MSVCRT_fgetwc(file))
#define _UNGETC_(nch, file) do { MSVCRT_ungetwc(nch, file); consumed--; } while(0)
#ifdef SECURE
#define _FUNCTION_ static int MSVCRT_vfwscanf_s_l(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list ap)
#else /* SECURE */
#define _FUNCTION_ static int MSVCRT_vfwscanf_l(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list ap)
#endif /* SECURE */
#else /* WIDE_SCANF */
#define _GETC_(file) (consumed++, MSVCRT_fgetc(file))
#define _UNGETC_(nch, file) do { MSVCRT_ungetc(nch, file); consumed--; } while(0)
#ifdef SECURE
#define _FUNCTION_ static int MSVCRT_vfscanf_s_l(MSVCRT_FILE* file, const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#else /* SECURE */
#define _FUNCTION_ static int MSVCRT_vfscanf_l(MSVCRT_FILE* file, const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#endif /* SECURE */
#endif /* WIDE_SCANF */
#endif /* STRING */
#endif /* CONSOLE */
......@@ -265,7 +285,7 @@ _FUNCTION_ {
if (width>0) width--;
}
} else {
cur = 0; /* MaxPayneDemo Fix: .8 -> 0.8 */
cur = 0; /* Fix: .8 -> 0.8 */
}
/* handle decimals */
if (width!=0 && nch == *locale->locinfo->lconv->decimal_point) {
......@@ -339,12 +359,25 @@ _FUNCTION_ {
#endif /* WIDE_SCANF */
charstring: { /* read a word into a char */
char *sptr = suppress ? NULL : va_arg(ap, char*);
char *sptr_beg = sptr;
#ifdef SECURE
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned);
#else
unsigned size = UINT_MAX;
#endif
/* skip initial whitespace */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
/* read until whitespace */
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
if (!suppress) {
*sptr++ = _CHAR2SUPPORTED_(nch);
if(size>1) size--;
else {
*sptr_beg = 0;
return rd;
}
}
st++;
nch = _GETC_(file);
if (width>0) width--;
......@@ -355,12 +388,25 @@ _FUNCTION_ {
break;
widecharstring: { /* read a word into a wchar_t* */
MSVCRT_wchar_t *sptr = suppress ? NULL : va_arg(ap, MSVCRT_wchar_t*);
MSVCRT_wchar_t *sptr_beg = sptr;
#ifdef SECURE
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned);
#else
unsigned size = UINT_MAX;
#endif
/* skip initial whitespace */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
/* read until whitespace */
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
if (!suppress) *sptr++ = _WIDE2SUPPORTED_(nch);
if (!suppress) {
*sptr++ = _WIDE2SUPPORTED_(nch);
if(size>1) size--;
else {
*sptr_beg = 0;
return rd;
}
}
st++;
nch = _GETC_(file);
if (width>0) width--;
......@@ -389,10 +435,23 @@ _FUNCTION_ {
#endif /* WIDE_SCANF */
character: { /* read single character into char */
char *str = suppress ? NULL : va_arg(ap, char*);
char *pstr = str;
#ifdef SECURE
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned)/sizeof(char);
#else
unsigned size = UINT_MAX;
#endif
if (width == -1) width = 1;
while ((width != 0) && (nch != _EOF_))
while (width && (nch != _EOF_))
{
if (!suppress) *str++ = _CHAR2SUPPORTED_(nch);
if (!suppress) {
*str++ = _CHAR2SUPPORTED_(nch);
if(size) size--;
else {
*pstr = 0;
return rd;
}
}
st++;
width--;
nch = _GETC_(file);
......@@ -401,10 +460,23 @@ _FUNCTION_ {
break;
widecharacter: { /* read single character into a wchar_t */
MSVCRT_wchar_t *str = suppress ? NULL : va_arg(ap, MSVCRT_wchar_t*);
MSVCRT_wchar_t *pstr = str;
#ifdef SECURE
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned)/sizeof(MSVCRT_wchar_t);
#else
unsigned size = UINT_MAX;
#endif
if (width == -1) width = 1;
while ((width != 0) && (nch != _EOF_))
while (width && (nch != _EOF_))
{
if (!suppress) *str++ = _WIDE2SUPPORTED_(nch);
if (!suppress) {
*str++ = _WIDE2SUPPORTED_(nch);
if(size) size--;
else {
*pstr = 0;
return rd;
}
}
st++;
width--;
nch = _GETC_(file);
......@@ -437,6 +509,11 @@ _FUNCTION_ {
RTL_BITMAP bitMask;
ULONG *Mask;
int invert = 0; /* Set if we are NOT to find the chars */
#ifdef SECURE
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned)/sizeof(_CHAR_);
#else
unsigned size = UINT_MAX;
#endif
/* Init our bitmap */
Mask = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8);
......@@ -481,6 +558,11 @@ _FUNCTION_ {
st++;
nch = _GETC_(file);
if (width>0) width--;
if(size>1) size--;
else {
*str = 0;
return rd;
}
}
/* terminate */
if (!suppress) *sptr = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment