Blame SOURCES/screen-cc.patch

c18ec5
commit 6eb1f1426bfd99f88d927838d51eabc2b13e73af
c18ec5
Author: Miroslav Lichvar <mlichvar@redhat.com>
c18ec5
Date:   Thu Jan 13 17:37:47 2011 +0100
c18ec5
c18ec5
    Avoid dereferencing null pointer in utmp.c.
c18ec5
c18ec5
diff --git a/src/utmp.c b/src/utmp.c
c18ec5
index aae1948..fa8b87b 100644
c18ec5
--- a/src/utmp.c
c18ec5
+++ b/src/utmp.c
c18ec5
@@ -575,7 +575,7 @@ struct win *wi;
c18ec5
     return ut_delete_user(slot, u.ut_pid, 0, 0) != 0;
c18ec5
 #endif
c18ec5
 #ifdef HAVE_UTEMPTER
c18ec5
-  if (eff_uid && wi->w_ptyfd != -1)
c18ec5
+  if (eff_uid && wi && wi->w_ptyfd != -1)
c18ec5
     {
c18ec5
       /* sigh, linux hackers made the helper functions void */
c18ec5
       if (SLOT_USED(u))
c18ec5
c18ec5
commit 4ebd6db10c712eb56d4e61f1a8d4a41d0465ed89
c18ec5
Author: Miroslav Lichvar <mlichvar@redhat.com>
c18ec5
Date:   Thu Jan 13 17:36:06 2011 +0100
c18ec5
c18ec5
    Add more tty checks.
c18ec5
c18ec5
diff --git a/src/extern.h b/src/extern.h
c18ec5
index 2b9722e..c787d99 100644
c18ec5
--- a/src/extern.h
c18ec5
+++ b/src/extern.h
c18ec5
@@ -110,6 +110,7 @@ extern void  brktty __P((int));
c18ec5
 extern struct baud_values *lookup_baud __P((int bps));
c18ec5
 extern int   SetBaud __P((struct mode *, int, int));
c18ec5
 extern int   SttyMode __P((struct mode *, char *));
c18ec5
+extern int   CheckTtyname __P((char *));
c18ec5
 
c18ec5
 
c18ec5
 /* mark.c */
c18ec5
diff --git a/src/screen.c b/src/screen.c
c18ec5
index 3dde3b4..cc8f565 100644
c18ec5
--- a/src/screen.c
c18ec5
+++ b/src/screen.c
c18ec5
@@ -970,8 +970,13 @@ char **av;
c18ec5
 	else \
c18ec5
 	  attach_tty = ""; \
c18ec5
       } \
c18ec5
-    else if (stat(attach_tty, &st)) \
c18ec5
-      Panic(errno, "Cannot access '%s'", attach_tty); \
c18ec5
+    else \
c18ec5
+      { \
c18ec5
+	if (stat(attach_tty, &st)) \
c18ec5
+	  Panic(errno, "Cannot access '%s'", attach_tty); \
c18ec5
+	if (CheckTtyname(attach_tty)) \
c18ec5
+	  Panic(0, "Bad tty '%s'", attach_tty); \
c18ec5
+      } \
c18ec5
     if (strlen(attach_tty) >= MAXPATHLEN) \
c18ec5
       Panic(0, "TtyName too long - sorry."); \
c18ec5
   } while (0)
c18ec5
diff --git a/src/tty.sh b/src/tty.sh
c18ec5
index f2afd54..e264796 100644
c18ec5
--- a/src/tty.sh
c18ec5
+++ b/src/tty.sh
c18ec5
@@ -60,6 +60,7 @@ exit 0
c18ec5
 #include <sys/types.h>
c18ec5
 #include <signal.h>
c18ec5
 #include <fcntl.h>
c18ec5
+#include <sys/stat.h>
c18ec5
 #ifndef sgi
c18ec5
 # include <sys/file.h>
c18ec5
 #endif
c18ec5
@@ -1506,6 +1507,19 @@ int ibaud, obaud;
c18ec5
   return 0;
c18ec5
 }
c18ec5
 
c18ec5
+
c18ec5
+int
c18ec5
+CheckTtyname (tty)
c18ec5
+char *tty;
c18ec5
+{
c18ec5
+  struct stat st;
c18ec5
+
c18ec5
+  if (lstat(tty, &st) || !S_ISCHR(st.st_mode) ||
c18ec5
+     (st.st_nlink > 1 && strncmp(tty, "/dev/", 5)))
c18ec5
+    return -1;
c18ec5
+  return 0;
c18ec5
+}
c18ec5
+
c18ec5
 /*
c18ec5
  *  Write out the mode struct in a readable form
c18ec5
  */
c18ec5
diff --git a/src/utmp.c b/src/utmp.c
c18ec5
index afa0948..aae1948 100644
c18ec5
--- a/src/utmp.c
c18ec5
+++ b/src/utmp.c
c18ec5
@@ -361,7 +361,7 @@ RemoveLoginSlot()
c18ec5
       char *tty;
c18ec5
       debug("couln't zap slot -> do mesg n\n");
c18ec5
       D_loginttymode = 0;
c18ec5
-      if ((tty = ttyname(D_userfd)) && stat(tty, &stb) == 0 && (int)stb.st_uid == real_uid && ((int)stb.st_mode & 0777) != 0666)
c18ec5
+      if ((tty = ttyname(D_userfd)) && stat(tty, &stb) == 0 && (int)stb.st_uid == real_uid && !CheckTtyname(tty) && ((int)stb.st_mode & 0777) != 0666)
c18ec5
 	{
c18ec5
 	  D_loginttymode = (int)stb.st_mode & 0777;
c18ec5
 	  chmod(D_usertty, stb.st_mode & 0600);
c18ec5
@@ -387,7 +387,7 @@ RestoreLoginSlot()
c18ec5
     }
c18ec5
   UT_CLOSE;
c18ec5
   D_loginslot = (slot_t)0;
c18ec5
-  if (D_loginttymode && (tty = ttyname(D_userfd)))
c18ec5
+  if (D_loginttymode && (tty = ttyname(D_userfd)) && !CheckTtyname(tty))
c18ec5
     chmod(tty, D_loginttymode);
c18ec5
 }
c18ec5
 
c18ec5
@@ -853,7 +853,7 @@ getlogin()
c18ec5
 
c18ec5
   for (fd = 0; fd <= 2 && (tty = ttyname(fd)) == NULL; fd++)
c18ec5
     ;
c18ec5
-  if ((tty == NULL) || ((fd = open(UTMP_FILE, O_RDONLY)) < 0))
c18ec5
+  if ((tty == NULL) || CheckTtyname(tty) || ((fd = open(UTMP_FILE, O_RDONLY)) < 0))
c18ec5
     return NULL;
c18ec5
   tty = stripdev(tty);
c18ec5
   retbuf[0] = '\0';
c18ec5
c18ec5
commit 8e7fcb821dc7204a27d88707284e259444671c12
c18ec5
Author: Miroslav Lichvar <mlichvar@redhat.com>
c18ec5
Date:   Thu Jan 13 17:31:16 2011 +0100
c18ec5
c18ec5
    Don't assign address of auto variable to outer scope symbol.
c18ec5
c18ec5
diff --git a/src/socket.c b/src/socket.c
c18ec5
index 940034d..7507d75 100644
c18ec5
--- a/src/socket.c
c18ec5
+++ b/src/socket.c
c18ec5
@@ -722,6 +722,7 @@ struct msg *mp;
c18ec5
   char *args[MAXARGS];
c18ec5
   register int n;
c18ec5
   register char **pp = args, *p = mp->m.create.line;
c18ec5
+  char buf[20];
c18ec5
 
c18ec5
   nwin = nwin_undef;
c18ec5
   n = mp->m.create.nargs;
c18ec5
@@ -731,7 +732,6 @@ struct msg *mp;
c18ec5
   if (n)
c18ec5
     {
c18ec5
       int l, num;
c18ec5
-      char buf[20];
c18ec5
 
c18ec5
       l = strlen(p);
c18ec5
       if (IsNumColon(p, 10, buf, sizeof(buf)))
c18ec5
c18ec5
commit 2a0e0dc7e05b36f374a074f6627efece3695f8c7
c18ec5
Author: Miroslav Lichvar <mlichvar@redhat.com>
c18ec5
Date:   Thu Jan 13 17:24:04 2011 +0100
c18ec5
c18ec5
    Remove redundant if statements.
c18ec5
c18ec5
diff --git a/src/braille_tsi.c b/src/braille_tsi.c
c18ec5
index 6768291..6f84913 100644
c18ec5
--- a/src/braille_tsi.c
c18ec5
+++ b/src/braille_tsi.c
c18ec5
@@ -127,7 +127,6 @@ display_status_tsi()
c18ec5
   r = read(bd.bd_fd,ibuf,1);
c18ec5
   if (r != 1)
c18ec5
     return -1;
c18ec5
-  if (r != -1)
c18ec5
   if (ibuf[0] == 'V')
c18ec5
     r = read(bd.bd_fd, ibuf, 3);
c18ec5
   else
c18ec5
diff --git a/src/fileio.c b/src/fileio.c
c18ec5
index 88fbf64..bd29011 100644
c18ec5
--- a/src/fileio.c
c18ec5
+++ b/src/fileio.c
c18ec5
@@ -80,8 +80,6 @@ register char *str1, *str2;
c18ec5
     }
c18ec5
   else
c18ec5
     {
c18ec5
-      if (len1 == 0)
c18ec5
-	return 0;
c18ec5
       if ((cp = malloc((unsigned) len1 + add_colon + 1)) == NULL)
c18ec5
 	Panic(0, "%s", strnomem);
c18ec5
       cp[len1 + add_colon] = '\0';
c18ec5
c18ec5
commit e75e7a0cf5319e10aae0c45e17ce70d86ef2aee8
c18ec5
Author: Miroslav Lichvar <mlichvar@redhat.com>
c18ec5
Date:   Thu Jan 13 17:18:59 2011 +0100
c18ec5
c18ec5
    Set PAM_TTY item.
c18ec5
c18ec5
diff --git a/src/attacher.c b/src/attacher.c
c18ec5
index 1fab5b2..460f1ea 100644
c18ec5
--- a/src/attacher.c
c18ec5
+++ b/src/attacher.c
c18ec5
@@ -861,6 +861,7 @@ screen_builtin_lck()
c18ec5
 #ifdef USE_PAM
c18ec5
   pam_handle_t *pamh = 0;
c18ec5
   int pam_error;
c18ec5
+  char *tty_name;
c18ec5
 #else
c18ec5
   char *pass, mypass[16 + 1], salt[3];
c18ec5
 #endif
c18ec5
@@ -932,6 +933,15 @@ screen_builtin_lck()
c18ec5
       pam_error = pam_start("screen", ppp->pw_name, &PAM_conversation, &pamh);
c18ec5
       if (pam_error != PAM_SUCCESS)
c18ec5
 	AttacherFinit(SIGARG);		/* goodbye */
c18ec5
+
c18ec5
+      if (strncmp(attach_tty, "/dev/", 5) == 0)
c18ec5
+	tty_name = attach_tty + 5;
c18ec5
+      else
c18ec5
+	tty_name = attach_tty;
c18ec5
+      pam_error = pam_set_item(pamh, PAM_TTY, tty_name);
c18ec5
+      if (pam_error != PAM_SUCCESS)
c18ec5
+	AttacherFinit(SIGARG);		/* goodbye */
c18ec5
+
c18ec5
       pam_error = pam_authenticate(pamh, 0);
c18ec5
       pam_end(pamh, pam_error);
c18ec5
       PAM_conversation.appdata_ptr = 0;
c18ec5
c18ec5
commit eb2e13f633f9615e9b60f19e1649f46bd07b2802
c18ec5
Author: Miroslav Lichvar <mlichvar@redhat.com>
c18ec5
Date:   Thu Jan 13 17:16:59 2011 +0100
c18ec5
c18ec5
    Check return code from setgid/setuid.
c18ec5
c18ec5
diff --git a/src/attacher.c b/src/attacher.c
c18ec5
index 370d594..1fab5b2 100644
c18ec5
--- a/src/attacher.c
c18ec5
+++ b/src/attacher.c
c18ec5
@@ -185,8 +185,8 @@ int how;
c18ec5
 	  if (ret == SIG_POWER_BYE)
c18ec5
 	    {
c18ec5
 	      int ppid;
c18ec5
-	      setgid(real_gid);
c18ec5
-	      setuid(real_uid);
c18ec5
+	      if (setgid(real_gid) || setuid(real_uid))
c18ec5
+		Panic(errno, "setuid/gid");
c18ec5
 	      if ((ppid = getppid()) > 1)
c18ec5
 		Kill(ppid, SIGHUP);
c18ec5
 	      exit(0);
c18ec5
@@ -282,7 +282,10 @@ int how;
c18ec5
 #ifdef MULTIUSER
c18ec5
   if (!multiattach)
c18ec5
 #endif
c18ec5
-    setuid(real_uid);
c18ec5
+    {
c18ec5
+      if (setuid(real_uid))
c18ec5
+        Panic(errno, "setuid");
c18ec5
+    }
c18ec5
 #if defined(MULTIUSER) && defined(USE_SETEUID)
c18ec5
   else
c18ec5
     {
c18ec5
@@ -290,7 +293,8 @@ int how;
c18ec5
       xseteuid(real_uid); /* multi_uid, allow backend to send signals */
c18ec5
     }
c18ec5
 #endif
c18ec5
-  setgid(real_gid);
c18ec5
+  if (setgid(real_gid))
c18ec5
+    Panic(errno, "setgid");
c18ec5
   eff_uid = real_uid;
c18ec5
   eff_gid = real_gid;
c18ec5
 
c18ec5
@@ -486,7 +490,8 @@ AttacherFinit SIGDEFARG
c18ec5
 #ifdef MULTIUSER
c18ec5
   if (tty_oldmode >= 0)
c18ec5
     {
c18ec5
-      setuid(own_uid);
c18ec5
+      if (setuid(own_uid))
c18ec5
+        Panic(errno, "setuid");
c18ec5
       chmod(attach_tty, tty_oldmode);
c18ec5
     }
c18ec5
 #endif
c18ec5
@@ -504,11 +509,14 @@ AttacherFinitBye SIGDEFARG
c18ec5
   if (multiattach)
c18ec5
     exit(SIG_POWER_BYE);
c18ec5
 #endif
c18ec5
-  setgid(real_gid);
c18ec5
+  if (setgid(real_gid))
c18ec5
+    Panic(errno, "setgid");
c18ec5
 #ifdef MULTIUSER
c18ec5
-  setuid(own_uid);
c18ec5
+  if (setuid(own_uid))
c18ec5
+    Panic(errno, "setuid");
c18ec5
 #else
c18ec5
-  setuid(real_uid);
c18ec5
+  if (setuid(real_uid))
c18ec5
+    Panic(errno, "setuid");
c18ec5
 #endif
c18ec5
   /* we don't want to disturb init (even if we were root), eh? jw */
c18ec5
   if ((ppid = getppid()) > 1)
c18ec5
@@ -679,11 +687,14 @@ static sigret_t
c18ec5
 LockHup SIGDEFARG
c18ec5
 {
c18ec5
   int ppid = getppid();
c18ec5
-  setgid(real_gid);
c18ec5
+  if (setgid(real_gid))
c18ec5
+    Panic(errno, "setgid");
c18ec5
 #ifdef MULTIUSER
c18ec5
-  setuid(own_uid);
c18ec5
+  if (setuid(own_uid))
c18ec5
+    Panic(errno, "setuid");
c18ec5
 #else
c18ec5
-  setuid(real_uid);
c18ec5
+  if (setuid(real_uid))
c18ec5
+    Panic(errno, "setuid");
c18ec5
 #endif
c18ec5
   if (ppid > 1)
c18ec5
     Kill(ppid, SIGHUP);
c18ec5
@@ -710,11 +721,14 @@ LockTerminal()
c18ec5
       if ((pid = fork()) == 0)
c18ec5
         {
c18ec5
           /* Child */
c18ec5
-          setgid(real_gid);
c18ec5
+          if (setgid(real_gid))
c18ec5
+            Panic(errno, "setgid");
c18ec5
 #ifdef MULTIUSER
c18ec5
-          setuid(own_uid);
c18ec5
+          if (setuid(own_uid))
c18ec5
+            Panic(errno, "setuid");
c18ec5
 #else
c18ec5
-          setuid(real_uid);	/* this should be done already */
c18ec5
+          if (setuid(real_uid))   /* this should be done already */
c18ec5
+            Panic(errno, "setuid");
c18ec5
 #endif
c18ec5
           closeallfiles(0);	/* important: /etc/shadow may be open */
c18ec5
           execl(prg, "SCREEN-LOCK", NULL);