]> andersk Git - openssh.git/blobdiff - pty.c
- Prevent typedefs from being compiled more than once. Report from
[openssh.git] / pty.c
diff --git a/pty.c b/pty.c
index 0675583dcf3ab2288c19a7f0180071e92376cb87..bcd57fefd4f6c5b21162e61654078332b7841576 100644 (file)
--- a/pty.c
+++ b/pty.c
 #include "includes.h"
 RCSID("$Id$");
 
+#ifdef HAVE_UTIL_H
+# include <util.h>
+#endif /* HAVE_UTIL_H */
+
 #include "pty.h"
 #include "ssh.h"
 
-#ifdef HAVE_PTY_H
-#include <pty.h>
-#endif /* HAVE_PTY_H */
-
 /* Pty allocated with _getpty gets broken if we do I_PUSH:es to it. */
 #if defined(HAVE__GETPTY) || defined(HAVE_OPENPTY)
 #undef HAVE_DEV_PTMX
 #endif
 
+#ifdef HAVE_PTY_H
+# include <pty.h>
+#endif
+#if defined(HAVE_DEV_PTMX) && defined(HAVE_SYS_STROPTS_H)
+# include <sys/stropts.h>
+#endif
+
 #ifndef O_NOCTTY
 #define O_NOCTTY 0
 #endif
@@ -40,17 +47,19 @@ RCSID("$Id$");
  */
 
 int 
-pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
+pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
 {
-#ifdef HAVE_OPENPTY
+#if defined(HAVE_OPENPTY) || defined(BSD4_4)
        /* openpty(3) exists in OSF/1 and some other os'es */
+       char buf[64];
        int i;
 
-       i = openpty(ptyfd, ttyfd, namebuf, NULL, NULL);
+       i = openpty(ptyfd, ttyfd, buf, NULL, NULL);
        if (i < 0) {
                error("openpty: %.100s", strerror(errno));
                return 0;
        }
+       strlcpy(namebuf, buf, namebuflen);      /* possible truncation */
        return 1;
 #else /* HAVE_OPENPTY */
 #ifdef HAVE__GETPTY
@@ -65,7 +74,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
                error("_getpty: %.100s", strerror(errno));
                return 0;
        }
-       strcpy(namebuf, slave);
+       strlcpy(namebuf, slave, namebuflen);
        /* Open the slave side. */
        *ttyfd = open(namebuf, O_RDWR | O_NOCTTY);
        if (*ttyfd < 0) {
@@ -75,7 +84,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
        }
        return 1;
 #else /* HAVE__GETPTY */
-#ifdef HAVE_DEV_PTMX
+#if defined(HAVE_DEV_PTMX)
        /*
         * This code is used e.g. on Solaris 2.x.  (Note that Solaris 2.3
         * also has bsd-style ptys, but they simply do not work.)
@@ -99,7 +108,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
        pts = ptsname(ptm);
        if (pts == NULL)
                error("Slave pty side name could not be obtained.");
-       strcpy(namebuf, pts);
+       strlcpy(namebuf, pts, namebuflen);
        *ptyfd = ptm;
 
        /* Open the slave side. */
@@ -130,7 +139,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
        name = ttyname(*ptyfd);
        if (!name)
                fatal("Open of /dev/ptc returns device for which ttyname fails.");
-       strcpy(namebuf, name);
+       strlcpy(namebuf, name, namebuflen);
        *ttyfd = open(name, O_RDWR | O_NOCTTY);
        if (*ttyfd < 0) {
                error("Could not open pty slave side %.100s: %.100s",
@@ -154,8 +163,8 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf)
                *ptyfd = open(buf, O_RDWR | O_NOCTTY);
                if (*ptyfd < 0)
                        continue;
-               snprintf(namebuf, sizeof buf, "/dev/tty%c%c", ptymajors[i / num_minors],
-                        ptyminors[i % num_minors]);
+               snprintf(namebuf, namebuflen, "/dev/tty%c%c",
+                   ptymajors[i / num_minors], ptyminors[i % num_minors]);
 
                /* Open the slave side. */
                *ttyfd = open(namebuf, O_RDWR | O_NOCTTY);
This page took 0.046301 seconds and 4 git commands to generate.