Eigenschaftsänderungen: debian ___________________________________________________________________ Hinzugefügt: svn:ignore + *.log *.debhelper *.substvars files Index: debian/changelog =================================================================== --- debian/changelog (Revision 18430) +++ debian/changelog (Arbeitskopie) @@ -1,3 +1,10 @@ +univention-thin-client-login (6.1.1-1) unstable; urgency=low + + * Fix file descriptor leak in univention-session (Bug #18879) + * Fix compiler warning and typo in Makefile. + + -- Philipp Hahn Thu, 08 Jul 2010 15:42:23 +0200 + univention-thin-client-login (6.1.0-1) unstable; urgency=low * bump version for UCS TCS compatibility (Bug #17543) Index: src/script.c =================================================================== --- src/script.c (Revision 18430) +++ src/script.c (Arbeitskopie) @@ -78,7 +78,7 @@ get_command_args ( buffer, p, MAX_CMD_ARGS ); - if (debug_level && argv ) + if (debug_level) { int i; debug_printf ( "args: "); Index: src/command_socket.c =================================================================== --- src/command_socket.c (Revision 18430) +++ src/command_socket.c (Arbeitskopie) @@ -85,7 +85,7 @@ get_command_args ( buffer, p, MAX_CMD_ARGS ); - if (debug_level && argv ) + if (debug_level) { int i; debug_printf ( "args: "); @@ -102,7 +102,7 @@ /* create a new connection */ int command_socket_handler ( int fd ) { - int len = sizeof ( sock_name ); + socklen_t len = sizeof ( sock_name ); int new_fd = accept ( sock_fd, (struct sockaddr*) &sock_name, &len ); if (new_fd != -1) { add_read_fd ( new_fd, command_socket_client_handler ); Index: src/Makefile =================================================================== --- src/Makefile (Revision 18430) +++ src/Makefile (Arbeitskopie) @@ -42,4 +42,4 @@ install -m 755 client-run ${DESTDIR}/usr/bin/univention-client-run clean: - rm -f ${OBJS} ${OBJS} ${SRV_OBJS} ${CL_OBJS} {$CLR_OBJS} *~ ${PROGS} ${LIB} + ${RM} ${OBJS} ${OBJS} ${SRV_OBJS} ${CL_OBJS} ${CLR_OBJS} *~ ${PROGS} ${LIB} Index: src/connection.c =================================================================== --- src/connection.c (Revision 18430) +++ src/connection.c (Arbeitskopie) @@ -40,6 +40,7 @@ #include #include #include +#include extern int errno; @@ -71,23 +72,74 @@ return 0; } +/* + * Move file descriptor and mark as CLOSE-ON-EXEC. + */ +static int move_fd(int oldfd, int newfd) { + int flags; + int tmpfd; + + if (oldfd != newfd) + tmpfd = dup2(oldfd, newfd); + else + tmpfd = newfd; + if (tmpfd != newfd) + fatal_perror("Error dup2 failed\n"); + flags = fcntl(tmpfd, F_GETFD); + if (flags == -1) + fatal_perror("Error getting tmpfd status\n"); + flags |= FD_CLOEXEC; + if (fcntl(tmpfd, F_SETFD, flags) == -1) + fatal_perror("Error setting tmpfd status\n"); + + return tmpfd; +} + +/* + * Open /dev/null on fd in mode given by flags. + */ +static void open_dev_null(int fd, int flags) { + int tmpfd; + + close(fd); /* ignore error if already closed. */ + tmpfd = open("/dev/null", flags); + if (tmpfd < 0) + fatal_perror("Error opening /dev/null\n"); + if (tmpfd != fd) { + int ret; + + ret = dup2(tmpfd, fd); + if (ret < 0) + fatal_perror("Error dup2 failed\n"); + ret = close(tmpfd); + if (ret < 0) + fatal_perror("Error closing fd\n"); + } +} + +/* + * Clone FDs for client<->server communication inherited from SESSION_RSH + * to private FDs and mark them as CLOSE-ON-EXEC. + * Re-open STDIN and STDOUT as /dev/null to protect channel from non-protocol + * data. STDERR uses a separate channel and needs not to be changed; keep it + * for debugging. + * + * FD 3 and 4 are used to not mix with STDIN=0, STDOUT=1 and STDERR=2. + * Don't use dup() after closing previous FDs with close()! + */ void init_server_pipes ( void ) { - /* FIXME: what is fd 3? maybe use dup() instead */ - send_fd = dup2 ( STDOUT_FILENO, 3 ); - if ( send_fd < 0 ) - fatal_perror ( "dup failed" ); - close ( STDOUT_FILENO ); + send_fd = move_fd(STDOUT_FILENO, 3); if ( debug_level ) debug_printf ( "to_client fd=%d\n", send_fd ); - /* FIXME: see above */ - recv_fd = dup2 ( STDIN_FILENO, 4); - if ( recv_fd < 0 ) - fatal_perror ( "dup failed" ); - close ( STDIN_FILENO ); + open_dev_null(STDOUT_FILENO, O_WRONLY); + + recv_fd = move_fd(STDIN_FILENO, 4); add_read_fd ( recv_fd, connection_read_handler ); if ( debug_level ) debug_printf ( "from_client fd=%d\n", recv_fd ); + open_dev_null(STDIN_FILENO, O_RDONLY); + return; } Index: src/signals.c =================================================================== --- src/signals.c (Revision 18430) +++ src/signals.c (Arbeitskopie) @@ -67,7 +67,9 @@ void __unblock_signals ( void ) { + /* sigset_t sigset; + */ if ( (sig_block_count--) != 0 ) return; sigprocmask ( SIG_UNBLOCK, &block_mask, NULL ); Index: src/protocol.h =================================================================== --- src/protocol.h (Revision 18430) +++ src/protocol.h (Arbeitskopie) @@ -34,3 +34,4 @@ void send_command ( char * buffer ); void recv_command_fd ( char * buffer, int buflen, int recv_fd, int send_fd ); void recv_command ( char * buffer, int buflen ); +void init_server ( void );