[1/2] msvcrt: Add some overflow tests for strftime/wcsftime.
Dmitry Timoshkov
dmitry at baikal.ru
Tue Jan 10 23:46:26 CST 2012
If there is a need for more tests please let me know.
---
dlls/msvcrt/tests/time.c | 28 +++++++++++++++++++++++-----
1 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/dlls/msvcrt/tests/time.c b/dlls/msvcrt/tests/time.c
index a7790d5..50dc72e 100644
--- a/dlls/msvcrt/tests/time.c
+++ b/dlls/msvcrt/tests/time.c
@@ -48,11 +48,13 @@ static int* (__cdecl *p__daylight)(void);
static int* (__cdecl *p___p__daylight)(void);
static size_t (__cdecl *p_strftime)(char *, size_t, const char *, const struct tm *);
static size_t (__cdecl *p_wcsftime)(wchar_t *, size_t, const wchar_t *, const struct tm *);
+static char* (__cdecl *p_setlocale)(int, const char *);
static void init(void)
{
HMODULE hmod = LoadLibrary("msvcrt.dll");
+ p_setlocale = (void*)GetProcAddress(hmod, "setlocale");
p_gmtime32 = (void*)GetProcAddress(hmod, "_gmtime32");
p_gmtime = (void*)GetProcAddress(hmod, "gmtime");
p_gmtime32_s = (void*)GetProcAddress(hmod, "_gmtime32_s");
@@ -580,10 +582,10 @@ static void test_strftime(void)
static const wchar_t cW[] = { '%','c',0 };
static const char expected[] = "01/01/70 00:00:00";
time_t gmt;
- struct tm* gmt_tm;
+ struct tm *gmt_tm;
char buf[256], bufA[256];
WCHAR bufW[256];
- long retA, retW;
+ long ret, retA, retW;
if (!p_strftime || !p_wcsftime || !p_gmtime)
{
@@ -591,18 +593,31 @@ static void test_strftime(void)
return;
}
- setlocale(LC_TIME, "C");
+ p_setlocale(LC_TIME, "C");
gmt = 0;
gmt_tm = p_gmtime(&gmt);
ok(gmt_tm != NULL, "gmtime failed\n");
- retA = strftime(bufA, 256, "%c", gmt_tm);
+ retA = p_strftime(bufA, 8, "%c", gmt_tm);
+ ok(retA == 0, "expected 0, got %ld\n", retA);
+ retA = p_strftime(bufA, 17, "%c", gmt_tm);
+ ok(retA == 0, "expected 0, got %ld\n", retA);
+
+ retA = p_strftime(bufA, 256, "%c", gmt_tm);
todo_wine {
ok(retA == 17, "expected 17, got %ld\n", retA);
ok(strcmp(bufA, expected) == 0, "expected %s, got %s\n", expected, bufA);
}
- retW = wcsftime(bufW, 256, cW, gmt_tm);
+ ret = p_strftime(buf, retA, "%c", gmt_tm);
+ ok(ret == 0, "expected 0, got %ld\n", ret);
+
+ retW = p_wcsftime(bufW, 8, cW, gmt_tm);
+ ok(retW == 0, "expected 0, got %ld\n", retW);
+ retW = p_wcsftime(bufW, 17, cW, gmt_tm);
+ ok(retW == 0 /* Vista+ */ || broken(retW == 17), "expected 0, got %ld\n", retW);
+
+ retW = p_wcsftime(bufW, 256, cW, gmt_tm);
todo_wine
ok(retW == 17, "expected 17, got %ld\n", retW);
ok(retA == retW, "expected %ld, got %ld\n", retA, retW);
@@ -610,6 +625,9 @@ todo_wine
retA = WideCharToMultiByte(CP_ACP, 0, bufW, retW, buf, 256, NULL, NULL);
buf[retA] = 0;
ok(strcmp(bufA, buf) == 0, "expected %s, got %s\n", bufA, buf);
+
+ ret = p_wcsftime(bufW, retW, cW, gmt_tm);
+ ok(ret == 0 /* Vista+ */ || broken(ret == retW), "expected 0, got %ld\n", ret);
}
START_TEST(time)
--
1.7.7.4
More information about the wine-patches
mailing list