diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-10-10 15:10:33 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-10-10 15:10:33 +0000 |
commit | bb7631942dcc6370156118c834fe56c8da632dff (patch) | |
tree | 7dd8d7b88d3d2fec5b00e81a8b830d9cf5dbe5d0 | |
parent | 6bf4b0ac08bc472a2f11aa0c7fa5d55f03bc8604 (diff) |
Don't ignore $TERMCAP, $TERMINFO, $TERMINFO_DIRS, $TERMPATH, and $HOME
if root but not setugid.
Fix select usage to deal with an arbitrary number of fd's. This code
is not compiled since we use poll(2).
-rw-r--r-- | lib/libcurses/base/lib_getch.c | 38 | ||||
-rw-r--r-- | lib/libcurses/curses.3tbl | 7 | ||||
-rw-r--r-- | lib/libcurses/curses.priv.h | 6 | ||||
-rw-r--r-- | lib/libcurses/ncurses_cfg.h | 1 | ||||
-rw-r--r-- | lib/libcurses/tty/lib_twait.c | 46 | ||||
-rw-r--r-- | lib/libcurses/tty/tty_update.c | 15 |
6 files changed, 69 insertions, 44 deletions
diff --git a/lib/libcurses/base/lib_getch.c b/lib/libcurses/base/lib_getch.c index 0b37e2190c6..ca60de8dddc 100644 --- a/lib/libcurses/base/lib_getch.c +++ b/lib/libcurses/base/lib_getch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_getch.c,v 1.7 2000/10/08 22:46:58 millert Exp $ */ +/* $OpenBSD: lib_getch.c,v 1.8 2000/10/10 15:10:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -53,34 +53,40 @@ int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ static int kbd_mouse_read(unsigned char *p) { - fd_set fdset; + fd_set *fdset; + size_t fdsetsize; int nums = SP->_ifd + 1; + if (SP->_checkfd >= 0 && SP->_checkfd >= nums) + nums = SP->_checkfd + 1; + if (SP->_mouse_fd >= 0 && SP->_mouse_fd >= nums) + nums = SP->_mouse_fd + 1; + fdsetsize = howmany(nums, NFDBITS) * sizeof(fd_mask); + fdset = malloc(fdsetsize); + if (fdset == NULL) + return -1; + for (;;) { - FD_ZERO(&fdset); - FD_SET(SP->_ifd, &fdset); - if (SP->_checkfd >= 0) { - FD_SET(SP->_checkfd, &fdset); - if (SP->_checkfd >= nums) - nums = SP->_checkfd + 1; - } - if (SP->_mouse_fd >= 0) { - FD_SET(SP->_mouse_fd, &fdset); - if (SP->_mouse_fd >= nums) - nums = SP->_mouse_fd + 1; - } - if (select(nums, &fdset, NULL, NULL, NULL) >= 0) { + memset(fdset, 0, fdsetsize); + FD_SET(SP->_ifd, fdset); + if (SP->_checkfd >= 0) + FD_SET(SP->_checkfd, fdset); + if (SP->_mouse_fd >= 0) + FD_SET(SP->_mouse_fd, fdset); + if (select(nums, fdset, NULL, NULL, NULL) >= 0) { int n; if (SP->_mouse_fd >= 0 - && FD_ISSET(SP->_mouse_fd, &fdset)) { /* Prefer mouse */ + && FD_ISSET(SP->_mouse_fd, fdset)) { /* Prefer mouse */ n = read(SP->_mouse_fd, p, 1); } else { n = read(SP->_ifd, p, 1); } + free(fdset); return n; } if (errno != EINTR) { + free(fdset); return -1; } } diff --git a/lib/libcurses/curses.3tbl b/lib/libcurses/curses.3tbl index 01fb9ed4c35..434f675bf54 100644 --- a/lib/libcurses/curses.3tbl +++ b/lib/libcurses/curses.3tbl @@ -1,5 +1,5 @@ '\" t -.\" $OpenBSD: curses.3tbl,v 1.16 2000/10/08 22:46:54 millert Exp $ +.\" $OpenBSD: curses.3tbl,v 1.17 2000/10/10 15:10:29 millert Exp $ .\" .\"*************************************************************************** .\" Copyright (c) 1998,1999 Free Software Foundation, Inc. * @@ -696,9 +696,8 @@ This is a list of filenames separated by colons (i.e., ":"). If the TERMPATH symbol is not set, \fBcurses\fR looks in the files /etc/termcap, /usr/share/termcap and $HOME/.termcap, in that order. .PP -The library may be configured to disregard the following variables when the -current user is the superuser (root), or if the application uses setuid or -setgid permissions: +The library will disregard the following variables when the +application uses setuid or setgid permissions: $TERMCAP, $TERMINFO, $TERMINFO_DIRS, $TERMPATH, as well as $HOME. .SH FILES .TP 5 diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index 3327b4d97cd..30fff8b8bcf 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.priv.h,v 1.29 2000/10/08 22:46:55 millert Exp $ */ +/* $OpenBSD: curses.priv.h,v 1.30 2000/10/10 15:10:29 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -151,7 +151,11 @@ extern int errno; * point to custom terminfo/termcap locations. */ #ifdef USE_ROOT_ENVIRON +#ifdef __OpenBSD__ +#define use_terminfo_vars() (!issetugid()) +#else #define use_terminfo_vars() 1 +#endif #else #define use_terminfo_vars() _nc_env_access() extern int _nc_env_access(void); diff --git a/lib/libcurses/ncurses_cfg.h b/lib/libcurses/ncurses_cfg.h index 4895cb22993..b5fc60b4c78 100644 --- a/lib/libcurses/ncurses_cfg.h +++ b/lib/libcurses/ncurses_cfg.h @@ -132,6 +132,7 @@ #define USE_DATABASE 1 #define USE_GETCAP 1 #define USE_HASHMAP 1 +#define USE_ROOT_ENVIRON 1 /* #define USE_SIGWINCH 1 */ #include <ncurses_def.h> diff --git a/lib/libcurses/tty/lib_twait.c b/lib/libcurses/tty/lib_twait.c index 5c038bd91df..f882f915b71 100644 --- a/lib/libcurses/tty/lib_twait.c +++ b/lib/libcurses/tty/lib_twait.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_twait.c,v 1.6 2000/10/08 22:47:05 millert Exp $ */ +/* $OpenBSD: lib_twait.c,v 1.7 2000/10/10 15:10:32 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -116,7 +116,10 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) struct pollfd fds[2]; #elif defined(__BEOS__) #elif HAVE_SELECT - static fd_set set; + static fd_set *set; + static size_t setsize; + size_t nsetsize; + int readfd; #endif long starttime, returntime; @@ -180,29 +183,38 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) milliseconds = 0; } #elif HAVE_SELECT + if (mode & 1) { + count = SP->_ifd; + readfd = SP->_ifd; + } + if ((mode & 2) && (fd = SP->_mouse_fd) >= 0) { + count = max(fd, count); + readfd = fd; + } + + /* + * grow set as needed. + */ + nsetsize = howmany(count, NFDBITS) * sizeof(fd_mask); + if (setsize == 0 || setsize < nsetsize) { + setsize = nsetsize; + set = _nc_doalloc(set, setsize); + } + /* * select() modifies the fd_set arguments; do this in the * loop. */ - FD_ZERO(&set); - - if (mode & 1) { - FD_SET(SP->_ifd, &set); - count = SP->_ifd + 1; - } - if ((mode & 2) - && (fd = SP->_mouse_fd) >= 0) { - FD_SET(fd, &set); - count = max(fd, count) + 1; - } + memset(set, 0, setsize); + FD_SET(readfd, set); if (milliseconds >= 0) { struct timeval ntimeout; ntimeout.tv_sec = milliseconds / 1000; ntimeout.tv_usec = (milliseconds % 1000) * 1000; - result = select(count, &set, NULL, NULL, &ntimeout); + result = select(count + 1, set, NULL, NULL, &ntimeout); } else { - result = select(count, &set, NULL, NULL, NULL); + result = select(count + 1, set, NULL, NULL, NULL); } #endif @@ -253,10 +265,10 @@ _nc_timed_wait(int mode, int milliseconds, int *timeleft) #elif HAVE_SELECT if ((mode & 2) && (fd = SP->_mouse_fd) >= 0 - && FD_ISSET(fd, &set)) + && FD_ISSET(fd, set)) result |= 2; if ((mode & 1) - && FD_ISSET(SP->_ifd, &set)) + && FD_ISSET(SP->_ifd, set)) result |= 1; #endif } else diff --git a/lib/libcurses/tty/tty_update.c b/lib/libcurses/tty/tty_update.c index ef52d7f7a11..25f04b0339e 100644 --- a/lib/libcurses/tty/tty_update.c +++ b/lib/libcurses/tty/tty_update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_update.c,v 1.12 2000/10/08 22:47:05 millert Exp $ */ +/* $OpenBSD: tty_update.c,v 1.13 2000/10/10 15:10:32 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -256,16 +256,19 @@ check_pending(void) have_pending = TRUE; } #elif HAVE_SELECT - fd_set fdset; + fd_set *fdset; struct timeval ktimeout; ktimeout.tv_sec = ktimeout.tv_usec = 0; - FD_ZERO(&fdset); - FD_SET(SP->_checkfd, &fdset); - if (select(SP->_checkfd + 1, &fdset, NULL, NULL, &ktimeout) != 0) { - have_pending = TRUE; + fdset = calloc(howmany(SP->_checkfd + 1, NFDBITS), sizeof(fd_mask)); + if (fdset != NULL) { + FD_SET(SP->_checkfd, fdset); + if (select(SP->_checkfd + 1, fdset, NULL, NULL, &ktimeout) != 0) { + have_pending = TRUE; + } + free(fdset); } #endif } |