Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: fix segfault in uv_guess_handle()
Browse files Browse the repository at this point in the history
Fixes #293.
  • Loading branch information
bnoordhuis committed Jan 17, 2012
1 parent 0e6e4ab commit bf8ccfc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/unix/tty.c
Expand Up @@ -120,17 +120,15 @@ 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)) {
return UV_TTY;
}

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)) {
Expand Down
2 changes: 2 additions & 0 deletions test/test-tty.c
Expand Up @@ -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.
Expand Down

0 comments on commit bf8ccfc

Please sign in to comment.