msvcrt: _setmode should check if file descriptor is valid.

This commit is contained in:
Iván Matellanes 2015-08-03 21:32:53 +02:00 committed by Alexandre Julliard
parent e2659db454
commit ea2798f1ce
2 changed files with 15 additions and 0 deletions

View File

@ -2833,6 +2833,11 @@ int CDECL MSVCRT__setmode(int fd,int mode)
return -1;
}
if(info == &MSVCRT___badioinfo) {
*MSVCRT__errno() = MSVCRT_EBADF;
return -1;
}
if(mode == MSVCRT__O_BINARY) {
info->wxflag &= ~WX_TEXT;
info->exflag &= ~(EF_UTF8|EF_UTF16);

View File

@ -1789,6 +1789,16 @@ static void test_setmode(void)
return;
}
errno = 0xdeadbeef;
ret = _setmode(-2, 0);
ok(ret == -1, "_setmode returned %x, expected -1\n", ret);
ok(errno == EINVAL, "errno = %d\n", errno);
errno = 0xdeadbeef;
ret = _setmode(-2, _O_TEXT);
ok(ret == -1, "_setmode returned %x, expected -1\n", ret);
ok(errno == EBADF, "errno = %d\n", errno);
fd = _open(name, _O_CREAT|_O_WRONLY, _S_IWRITE);
ok(fd != -1, "failed to open file\n");