=?UTF-8?Q?Micha=C5=82=20Janiszewski=20?=: msvcrt: Update size checks for secure scanf versions.
Alexandre Julliard
julliard at winehq.org
Mon Jul 9 16:00:35 CDT 2018
Module: wine
Branch: master
Commit: 08d98f0ff83d664fa08208fed19cb90140e2ff10
URL: https://source.winehq.org/git/wine.git/?a=commit;h=08d98f0ff83d664fa08208fed19cb90140e2ff10
Author: Michał Janiszewski <janisozaur at gmail.com>
Date: Mon Jul 9 14:45:28 2018 +0200
msvcrt: Update size checks for secure scanf versions.
Signed-off-by: Michał Janiszewski <janisozaur at gmail.com>
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msvcrt/scanf.h | 4 ++--
dlls/msvcrt/tests/scanf.c | 9 ++++++++-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h
index 734fe8b..0903d69 100644
--- a/dlls/msvcrt/scanf.h
+++ b/dlls/msvcrt/scanf.h
@@ -548,13 +548,13 @@ _FUNCTION_ {
while (width && (nch != _EOF_))
{
if (!suppress) {
- *str++ = _CHAR2SUPPORTED_(nch);
if(size) size--;
else {
_UNLOCK_FILE_(file);
*pstr = 0;
return rd;
}
+ *str++ = _CHAR2SUPPORTED_(nch);
}
st++;
width--;
@@ -574,13 +574,13 @@ _FUNCTION_ {
while (width && (nch != _EOF_))
{
if (!suppress) {
- *str++ = _WIDE2SUPPORTED_(nch);
if(size) size--;
else {
_UNLOCK_FILE_(file);
*pstr = 0;
return rd;
}
+ *str++ = _WIDE2SUPPORTED_(nch);
}
st++;
width--;
diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c
index 359b079..b724483 100644
--- a/dlls/msvcrt/tests/scanf.c
+++ b/dlls/msvcrt/tests/scanf.c
@@ -282,10 +282,17 @@ static void test_sscanf_s(void)
ok(ret == 0, "Wrong number of arguments read: %d\n", ret);
ok(buf[0]=='\0', "buf = %s\n", buf);
- buf[0] = 'a';
+ memset(buf, 'a', sizeof(buf));
ret = psscanf_s("123", "%3c", buf, 2);
ok(ret == 0, "Wrong number of arguments read: %d\n", ret);
ok(buf[0]=='\0', "buf = %s\n", buf);
+ ok(buf[1]=='2', "buf[1] = %d\n", buf[1]);
+ ok(buf[2]=='a', "buf[2] = %d\n", buf[2]);
+
+ buf[3] = 'a';
+ buf[4] = 0;
+ ret = psscanf_s("123", "%3c", buf, 3);
+ ok(!strcmp("123a", buf), "buf = %s\n", buf);
i = 1;
ret = psscanf_s("123 123", "%s %d", buf, 2, &i);
More information about the wine-cvs
mailing list