unix: fix segfault in uv_guess_handle()

Fixes #293.
This commit is contained in:
Ben Noordhuis 2012-01-17 17:47:31 +01:00
parent 0e6e4abedc
commit bf8ccfce18
2 changed files with 4 additions and 4 deletions

View File

@ -120,8 +120,7 @@ uv_handle_type uv_guess_handle(uv_file file) {
struct stat s;
if (file < 0) {
uv__set_sys_error(NULL, EINVAL); /* XXX Need loop? */
return -1;
return UV_UNKNOWN_HANDLE;
}
if (isatty(file)) {
@ -129,8 +128,7 @@ uv_handle_type uv_guess_handle(uv_file file) {
}
if (fstat(file, &s)) {
uv__set_sys_error(NULL, errno); /* XXX Need loop? */
return -1;
return UV_UNKNOWN_HANDLE;
}
if (!S_ISSOCK(s.st_mode) && !S_ISFIFO(s.st_mode)) {

View File

@ -27,6 +27,8 @@ TEST_IMPL(tty) {
uv_tty_t tty;
uv_loop_t* loop = uv_default_loop();
ASSERT(UV_UNKNOWN_HANDLE == uv_guess_handle(-1));
/*
* Not necessarily a problem if this assert goes off. E.G you are piping
* this test to a file. 0 == stdin.