diff options
author | Tom Yu <tlyu@mit.edu> | 1997-12-05 02:48:58 +0000 |
---|---|---|
committer | Tom Yu <tlyu@mit.edu> | 1997-12-05 02:48:58 +0000 |
commit | 1c19e9f07aacf52c9775e0613cccca650b3268df (patch) | |
tree | 2e213cddc8f1d5fd1ef944013986ffed274ab766 /src | |
parent | 6344b9bc035f8ffd6dffe342ef89939ddabd532e (diff) | |
download | krb5-1c19e9f07aacf52c9775e0613cccca650b3268df.tar.gz krb5-1c19e9f07aacf52c9775e0613cccca650b3268df.tar.xz krb5-1c19e9f07aacf52c9775e0613cccca650b3268df.zip |
* getpty.c (pty_getpty): Fix checks on string lengths to account
for terminating nul character. Some whitespace fixups.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10313 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r-- | src/util/pty/ChangeLog | 5 | ||||
-rw-r--r-- | src/util/pty/getpty.c | 58 |
2 files changed, 31 insertions, 32 deletions
diff --git a/src/util/pty/ChangeLog b/src/util/pty/ChangeLog index b25dc16e71..ebe846adc4 100644 --- a/src/util/pty/ChangeLog +++ b/src/util/pty/ChangeLog @@ -1,3 +1,8 @@ +Thu Dec 4 21:48:12 1997 Tom Yu <tlyu@mit.edu> + + * getpty.c (pty_getpty): Fix checks on string lengths to account + for terminating nul character. Some whitespace fixups. + Wed Dec 3 17:16:44 1997 Tom Yu <tlyu@mit.edu> * pty_err.et: Add PTY_OPEN_SLAVE_TOOSHORT error code. diff --git a/src/util/pty/getpty.c b/src/util/pty/getpty.c index 8b97bff009..4fe6459a69 100644 --- a/src/util/pty/getpty.c +++ b/src/util/pty/getpty.c @@ -25,13 +25,13 @@ long pty_getpty (fd, slave, slavelength) int slavelength; int *fd; char *slave; { - char *cp; + char *cp; char *p; int i,ptynum; struct stat stb; -char slavebuf[1024]; + char slavebuf[1024]; #ifdef HAVE__GETPTY -char *slaveret; /*Temporary to hold pointer to slave*/ + char *slaveret; /*Temporary to hold pointer to slave*/ #endif /*HAVE__GETPTY*/ #ifdef HAVE_OPENPTY @@ -39,7 +39,7 @@ char *slaveret; /*Temporary to hold pointer to slave*/ if(openpty(fd, &slavefd, slave, (struct termios *) 0, (struct winsize *) 0)) return 1; -close(slavefd); + close(slavefd); return 0; #else /*HAVE_OPENPTY*/ #ifdef HAVE__GETPTY @@ -51,13 +51,13 @@ close(slavefd); * paths. */ if ((slaveret = _getpty(fd, O_RDWR|O_NDELAY, 0600, 0)) == 0) { - *fd = -1; - return PTY_GETPTY_NOPTY; + *fd = -1; + return PTY_GETPTY_NOPTY; } - if (strlen(slaveret) > slavelength) { - close(*fd); - *fd = -1; - return PTY_GETPTY_SLAVE_TOOLONG; + if (strlen(slaveret) > slavelength - 1) { + close(*fd); + *fd = -1; + return PTY_GETPTY_SLAVE_TOOLONG; } else strcpy(slave, slaveret); return 0; @@ -86,13 +86,11 @@ close(slavefd); #endif #endif if (p) { - if ( strlen(p) > slavelength) - { + if (strlen(p) > slavelength - 1) { close (*fd); *fd = -1; return PTY_GETPTY_SLAVE_TOOLONG; - } - + } strcpy(slave, p); return 0; } @@ -102,21 +100,19 @@ close(slavefd); return PTY_GETPTY_FSTAT; } ptynum = (int)(stb.st_rdev&0xFF); - sprintf(slavebuf, "/dev/ttyp%x", ptynum); - if ( strlen(slavebuf) > slavelength) { - close(*fd); - *fd = -1; - return PTY_GETPTY_SLAVE_TOOLONG; - } - strncpy ( slave, slavebuf, slavelength); + sprintf(slavebuf, "/dev/ttyp%x", ptynum); + if (strlen(slavebuf) > slavelength - 1) { + close(*fd); + *fd = -1; + return PTY_GETPTY_SLAVE_TOOLONG; + } + strncpy(slave, slavebuf, slavelength); return 0; - } else { - - for (cp = "pqrstuvwxyzPQRST";*cp; cp++) { + for (cp = "pqrstuvwxyzPQRST";*cp; cp++) { sprintf(slavebuf,"/dev/ptyXX"); - slavebuf[strlen("/dev/pty")] = *cp; - slavebuf[strlen("/dev/ptyp")] = '0'; + slavebuf[sizeof("/dev/pty")] = *cp; + slavebuf[sizeof("/dev/ptyp")] = '0'; if (stat(slavebuf, &stb) < 0) break; for (i = 0; i < 16; i++) { @@ -126,13 +122,12 @@ close(slavefd); /* got pty */ slavebuf[strlen("/dev/")] = 't'; - if ( strlen(slavebuf) > slavelength ) { - close ( *fd); + if (strlen(slavebuf) > slavelength -1) { + close(*fd); *fd = -1; -return PTY_GETPTY_SLAVE_TOOLONG; + return PTY_GETPTY_SLAVE_TOOLONG; } - strncpy ( slave, slavebuf, slavelength); - + strncpy(slave, slavebuf, slavelength); return 0; } } @@ -141,4 +136,3 @@ return PTY_GETPTY_SLAVE_TOOLONG; #endif /*HAVE__GETPTY*/ #endif /* HAVE_OPENPTY */ } - |