* Windows crash in ctime_r()
@ 2016-05-16 21:50 Michael Schoberg (mschoberg)
2016-05-17 1:24 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Michael Schoberg (mschoberg) @ 2016-05-16 21:50 UTC (permalink / raw)
To: fio@vger.kernel.org
I think I found an issue in os\windows\posix.c that results in a FIO crash (on Windows.) I'm including a patch that resolves the crash for us, but includes another (optional) fix.
Crash issue: possix.c - ctime_r() will reference a negative array index on Sunday. SYSTEMTIME states the days of the week as: "0=Sunday, .. , 6=Saturday." The "fix" can likely be dialed back to safely assume the days/months will adhere to how they're documented.
Optional - StringCchPrintfA() calls should allow for the string plus a NULL character. Instead, the value getting passed in is for the entire string size.
os/windows/posix.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/os/windows/posix.c b/os/windows/posix.c
index 41fc480..fd3d9ab 100755
--- a/os/windows/posix.c
+++ b/os/windows/posix.c
@@ -243,12 +243,12 @@ void Time_tToSystemTime(time_t dosTime, SYSTEMTIME *systemTime)
char* ctime_r(const time_t *t, char *buf)
{
SYSTEMTIME systime;
- const char * const dayOfWeek[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
+ const char * const dayOfWeek[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
const char * const monthOfYear[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
Time_tToSystemTime(*t, &systime);
/* We don't know how long `buf` is, but assume it's rounded up from the minimum of 25 to 32 */
- StringCchPrintfA(buf, 32, "%s %s %d %02d:%02d:%02d %04d", dayOfWeek[systime.wDayOfWeek - 1], monthOfYear[systime.wMonth - 1],
+ StringCchPrintfA(buf, 31, "%s %s %d %02d:%02d:%02d %04d", dayOfWeek[systime.wDayOfWeek % 7], monthOfYear[(systime.wMonth - 1) % 12],
systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, systime.wYear);
return buf;
}
@@ -888,7 +888,7 @@ struct dirent *readdir(DIR *dirp)
if (dirp->find_handle == INVALID_HANDLE_VALUE) {
char search_pattern[MAX_PATH];
- StringCchPrintfA(search_pattern, MAX_PATH, "%s\\*", dirp->dirname);
+ StringCchPrintfA(search_pattern, MAX_PATH-1, "%s\\*", dirp->dirname);
dirp->find_handle = FindFirstFileA(search_pattern, &find_data);
if (dirp->find_handle == INVALID_HANDLE_VALUE)
return NULL;
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: Windows crash in ctime_r()
2016-05-16 21:50 Windows crash in ctime_r() Michael Schoberg (mschoberg)
@ 2016-05-17 1:24 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2016-05-17 1:24 UTC (permalink / raw)
To: Michael Schoberg (mschoberg), fio@vger.kernel.org
On 05/16/2016 03:50 PM, Michael Schoberg (mschoberg) wrote:
> I think I found an issue in os\windows\posix.c that results in a FIO
> crash (on Windows.) I'm including a patch that resolves the crash for
> us, but includes another (optional) fix. > > Crash issue: possix.c -
> ctime_r() will reference a negative array index on Sunday. SYSTEMTIME
> states the days of the week as: "0=Sunday, .. , 6=Saturday." The "fix"
> can likely be dialed back to safely assume the days/months will adhere
> to how they're documented.
>
>
> Optional - StringCchPrintfA() calls should allow for the string plus a
> NULL character. Instead, the value getting passed in is for the entire
> string size.
Thanks, both look good, applied.
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-17 1:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-16 21:50 Windows crash in ctime_r() Michael Schoberg (mschoberg)
2016-05-17 1:24 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox