From: Sam Hartman Date: Tue, 1 Aug 1995 17:53:21 +0000 (+0000) Subject: Make interface change so getpty doesn't overwrite X-Git-Tag: krb5-1.0-beta6~1446 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1318afa6ca3f64e4ff009adb40d880f5b2bfce9f;p=krb5.git Make interface change so getpty doesn't overwrite user-supplied buffer. Allow for telnetd not knowing PID of slave process. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6374 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/pty/.Sanitize b/src/util/pty/.Sanitize new file mode 100644 index 000000000..b50536221 --- /dev/null +++ b/src/util/pty/.Sanitize @@ -0,0 +1,48 @@ +# Sanitize.in for Kerberos V5 + +# Each directory to survive it's way into a release will need a file +# like this one called "./.Sanitize". All keyword lines must exist, +# and must exist in the order specified by this file. Each directory +# in the tree will be processed, top down, in the following order. + +# Hash started lines like this one are comments and will be deleted +# before anything else is done. Blank lines will also be squashed +# out. + +# The lines between the "Do-first:" line and the "Things-to-keep:" +# line are executed as a /bin/sh shell script before anything else is +# done in this + +Do-first: + +# All files listed between the "Things-to-keep:" line and the +# "Files-to-sed:" line will be kept. All other files will be removed. +# Directories listed in this section will have their own Sanitize +# called. Directories not listed will be removed in their entirety +# with rm -rf. + +Things-to-keep: + +.cvsignore +ChangeLog +Makefile.in +configure.in +cleanup.c +getpty.c +initialize_slave.c +libpty.h +logwtmp.c +open_ctty.c +open_slave.c +pty-int.h +pty_err.et +update_utmp.c +update_wtmp.c +vhangup.c +void_assoc.c + +Things-to-lose: + +Do-last: + +# End of file. diff --git a/src/util/pty/ChangeLog b/src/util/pty/ChangeLog index 5becd6741..190e05ca4 100644 --- a/src/util/pty/ChangeLog +++ b/src/util/pty/ChangeLog @@ -1,3 +1,19 @@ + +Tue Aug 1 08:20:06 1995 Sam Hartman + + * cleanup.c (pty_cleanup): Allow pid to be zero (unknown). + + * pty-int.h: Define VHANG_FIRST and VHANG_LAST based on presence + of vhangup. + + * pty_err.et: Define PTY_GETPTY_SLAVE_TOOLONG + + * getpty.c (pty_getpty): Close slave side if we call openpty. + + (pty_getpty): Take length parameter; return error if it isn't big enough. + + + Tue Aug 1 12:06:14 1995 Ezra Peisach * open_ctty.c (pty_open_ctty): Fixed typo TIOCSTTY to TIOCSCTTY. diff --git a/src/util/pty/cleanup.c b/src/util/pty/cleanup.c index c2f883789..d9103a472 100644 --- a/src/util/pty/cleanup.c +++ b/src/util/pty/cleanup.c @@ -25,7 +25,7 @@ long pty_cleanup (slave, pid, update_utmp) char *slave; - pid_t pid; + pid_t pid; /* May be zero for unknown.*/ int update_utmp; { struct utmp ut; diff --git a/src/util/pty/getpty.c b/src/util/pty/getpty.c index 4033ad5ad..7968e4256 100644 --- a/src/util/pty/getpty.c +++ b/src/util/pty/getpty.c @@ -23,19 +23,23 @@ #include "libpty.h" #include "pty-int.h" -long pty_getpty (fd, slave) -int *fd; char *slave; +long pty_getpty (fd, slave, slavelength) + int slavelength; + int *fd; char *slave; { char c; char *p; int i,ptynum; struct stat stb; +char slavebuf[1024]; + #ifdef HAVE_OPENPTY int slavefd; if(openpty(fd, &slavefd, slave, (struct termios *) 0, (struct winsize *) 0)) return 1; +close(slavefd); return 0; #else @@ -59,6 +63,13 @@ int *fd; char *slave; #endif #endif if (p) { + if ( strlen(p) < slavelength) + { + close (*fd); + *fd = -1; + return PTY_GETPTY_SLAVE_TOOLONG; + } + strcpy(slave, p); return 0; } @@ -68,24 +79,37 @@ int *fd; char *slave; return PTY_GETPTY_FSTAT; } ptynum = (int)(stb.st_rdev&0xFF); - sprintf(slave, "/dev/ttyp%x", ptynum); + sprintf(slavebuf, "/dev/ttyp%x", ptynum); + if ( strlen(slavebuf) < slavelength) { + close(*fd); + *fd = -1; + return PTY_GETPTY_SLAVE_TOOLONG; + } + strncpy ( slave, slavebuf, slavelength); return 0; } else { for (c = 'p'; c <= 's'; c++) { - sprintf(slave,"/dev/ptyXX"); - slave[strlen("/dev/pty")] = c; - slave[strlen("/dev/ptyp")] = '0'; - if (stat(slave, &stb) < 0) + sprintf(slavebuf,"/dev/ptyXX"); + slavebuf[strlen("/dev/pty")] = c; + slavebuf[strlen("/dev/ptyp")] = '0'; + if (stat(slavebuf, &stb) < 0) break; for (i = 0; i < 16; i++) { - slave[sizeof("/dev/ptyp") - 1] = "0123456789abcdef"[i]; - *fd = open(slave, O_RDWR); + slavebuf[sizeof("/dev/ptyp") - 1] = "0123456789abcdef"[i]; + *fd = open(slavebuf, O_RDWR); if (*fd < 0) continue; /* got pty */ - slave[strlen("/dev/")] = 't'; + slavebuf[strlen("/dev/")] = 't'; + if ( strlen(slavebuf) < slavelength ) { + close ( *fd); + *fd = -1; +return PTY_GETPTY_SLAVE_TOOLONG; + } + strncpy ( slave, slavebuf, slavelength); + return 0; } } diff --git a/src/util/pty/libpty.h b/src/util/pty/libpty.h index f85dda55c..b8e9a5aa4 100644 --- a/src/util/pty/libpty.h +++ b/src/util/pty/libpty.h @@ -24,7 +24,7 @@ #ifdef __STDC__ /* use prototypes */ -long pty_getpty ( int *fd, char *slave); +long pty_getpty ( int *fd, char *slave, int slavelength); long pty_open_slave (const char *slave, int *fd); long pty_open_ctty (const char *slave, int *fd); diff --git a/src/util/pty/pty-int.h b/src/util/pty/pty-int.h index 56a7ac6e7..95d5dd220 100644 --- a/src/util/pty/pty-int.h +++ b/src/util/pty/pty-int.h @@ -76,6 +76,11 @@ #endif #endif +#if defined(HAVE_VHANGUP) +#define VHANG_first /* may not work under Ultrix*/ +#define VHANG_LAST +#endif + /* Internal functions */ #ifdef __STDC__ long ptyint_void_association(void); diff --git a/src/util/pty/pty_err.et b/src/util/pty/pty_err.et index a70d75571..0c28dfc2d 100644 --- a/src/util/pty/pty_err.et +++ b/src/util/pty/pty_err.et @@ -28,6 +28,8 @@ error_code PTY_GETPTY_FSTAT, "fstat of master pty failed" error_code PTY_GETPTY_NOPTY, "All terminal ports in use" +error_code PTY_GETPTY_SLAVE_TOOLONG, "buffer to hold slave pty name is too short" + error_code PTY_OPEN_SLAVE_OPENFAIL, "Failed to open slave side of pty" error_code PTY_OPEN_SLAVE_CHMODFAIL, "Failed to chmod slave side of pty"