Commit ea2798f1 authored by Iván Matellanes's avatar Iván Matellanes Committed by Alexandre Julliard

msvcrt: _setmode should check if file descriptor is valid.

parent e2659db4
......@@ -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);
......
......@@ -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");
......
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