[13138] in Athena Bugs

home help back first fref pref prev next nref lref last post

from: revised patch

daemon@ATHENA.MIT.EDU (Richard Basch)
Fri Jan 27 12:38:16 1995

Date: Fri, 27 Jan 1995 12:38:03 -0500
To: bugs@MIT.EDU
From: "Richard Basch" <basch@MIT.EDU>


1. Some re-ordering of header files. (It still needs more for compliance...)
2. Fixed the problem where it would overrun buffers.
3. Removed extraneous buffer manipulation.

-Richard

--- from.c	1995/01/20 00:50:26	1.1
+++ from.c	1995/01/27 17:35:16
@@ -13,25 +13,30 @@
 static char *rcsid = "$Id: from.c,v 1.1 1995/01/20 00:50:26 probe Exp probe $";
 #endif /* lint || SABER */
 
-#include <stdio.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <strings.h>
 #if defined(POSIX) || defined(_POSIX_SOURCE)
+#include <unistd.h>
 #include <stdlib.h>
+#include <termios.h>
 #else
 extern char *malloc();
 #endif
+
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/stat.h>
+
 #ifdef HESIOD
 #include <hesiod.h>
 #endif
-#include <ctype.h>
-#include <sys/stat.h>
+
 #ifdef SOLARIS
-#include <termios.h>
 #include <regexpr.h>
 #endif
+
 #define NOTOK (-1)
 #define OK 0
 #define DONE 1
@@ -281,8 +286,10 @@
 	if ((ioctl(1, TIOCGWINSZ, (void *)&windowsize) < 0) || 
 	    (windowsize.ws_col == 0))
 		windowsize.ws_col = 80;		/* default assume 80 */
+
 	/* for the console window timestamp */
 	linelength = windowsize.ws_col - 6;
+
 	if (linelength < 32)
 		linelength = 32;
 	
@@ -583,12 +590,12 @@
       fprintf (stderr, "from: out of memory");
       exit (1);
     }    
-  buf[0] = '\0';
-  buf[winlength] = '\0';
   if (from_field)
     strncpy(buf, from_field, winlength);
   else
     strncpy(buf, "<<unknown sender>>", winlength);
+  buf[winlength] = '\0';
+
   len = strlen(buf);
   if  (len < 30)
     len = 30;
@@ -599,13 +606,10 @@
       fprintf (stderr, "from: out of memory");
       exit (1);
     }    
-  buf1[0] = '\0';
-
-  if (winlength - len - 1 < 1)
-    subject_field = NULL;
 
-  if (subject_field)
-    strncpy(buf1, subject_field, winlength - len - 1);
+  if (winlength - len - 1 > 0)
+      strncpy(buf1, subject_field, winlength - len - 1);
+  buf1[winlength - len] = '\0';
   
   printf("%-30s %s\n", buf, buf1);
 

home help back first fref pref prev next nref lref last post