Blame SOURCES/screen-cc.patch

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