msvcrt: _setmode should check if file descriptor is valid.
This commit is contained in:
parent
e2659db454
commit
ea2798f1ce
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in New Issue