svn commit: trunk/busybox: coreutils editors libbb networking procp etc...

vda at busybox.net vda at busybox.net
Fri Oct 27 09:03:24 UTC 2006


Author: vda
Date: 2006-10-27 02:03:24 -0700 (Fri, 27 Oct 2006)
New Revision: 16452

Log:
get_terminal_width_height: do not pass insanely large values


Modified:
   trunk/busybox/coreutils/watch.c
   trunk/busybox/editors/vi.c
   trunk/busybox/libbb/xfuncs.c
   trunk/busybox/networking/telnet.c
   trunk/busybox/networking/wget.c
   trunk/busybox/procps/ps.c


Changeset:
Modified: trunk/busybox/coreutils/watch.c
===================================================================
--- trunk/busybox/coreutils/watch.c	2006-10-27 09:02:31 UTC (rev 16451)
+++ trunk/busybox/coreutils/watch.c	2006-10-27 09:03:24 UTC (rev 16452)
@@ -58,7 +58,6 @@
 			time_t t;
 
 			get_terminal_width_height(STDOUT_FILENO, &width, 0);
-			if (width < 1) width = 1; // paranoia
 			header = xrealloc(header, width--);
 			// '%-*s' pads header with spaces to the full width
 			snprintf(header, width, "Every %ds: %-*s", period, width, cmd);

Modified: trunk/busybox/editors/vi.c
===================================================================
--- trunk/busybox/editors/vi.c	2006-10-27 09:02:31 UTC (rev 16451)
+++ trunk/busybox/editors/vi.c	2006-10-27 09:03:24 UTC (rev 16452)
@@ -2039,7 +2039,7 @@
 {
 	signal(SIGWINCH, winch_sig);
 	if (ENABLE_FEATURE_VI_WIN_RESIZE)
-	   get_terminal_width_height(0, &columns, &rows);
+		get_terminal_width_height(0, &columns, &rows);
 	new_screen(rows, columns);	// get memory for virtual screen
 	redraw(TRUE);		// re-draw the screen
 }

Modified: trunk/busybox/libbb/xfuncs.c
===================================================================
--- trunk/busybox/libbb/xfuncs.c	2006-10-27 09:02:31 UTC (rev 16451)
+++ trunk/busybox/libbb/xfuncs.c	2006-10-27 09:03:24 UTC (rev 16452)
@@ -281,6 +281,8 @@
 
 	if (ioctl(fd, BLKGETSIZE, &size) >= 0) return size*512;
 
+	// FIXME: explain why lseek(SEEK_END) is not used here!
+
 	// If not, do a binary search for the last location we can read.  (Some
 	// block devices don't do BLKGETSIZE right.)
 
@@ -382,7 +384,8 @@
 // Die with an error message if we can't daemonize.
 void xdaemon(int nochdir, int noclose)
 {
-	if (daemon(nochdir, noclose)) bb_perror_msg_and_die("daemon");
+	if (daemon(nochdir, noclose))
+		bb_perror_msg_and_die("daemon");
 }
 #endif
 
@@ -416,23 +419,31 @@
 }
 
 /* It is perfectly ok to pass in a NULL for either width or for
- *  * height, in which case that value will not be set.  */
+ * height, in which case that value will not be set.  */
 int get_terminal_width_height(int fd, int *width, int *height)
 {
 	struct winsize win = { 0, 0, 0, 0 };
 	int ret = ioctl(fd, TIOCGWINSZ, &win);
-	if (!win.ws_row) {
-		char *s = getenv("LINES");
-		if (s) win.ws_row = atoi(s);
+
+	if (height) {
+		if (!win.ws_row) {
+			char *s = getenv("LINES");
+			if (s) win.ws_row = atoi(s);
+		}
+		if (win.ws_row <= 1 || win.ws_row >= 30000)
+			win.ws_row = 24;
+		*height = (int) win.ws_row;
 	}
-	if (win.ws_row <= 1) win.ws_row = 24;
-	if (!win.ws_col) {
-		char *s = getenv("COLUMNS");
-		if (s) win.ws_col = atoi(s);
+
+	if (width) {
+		if (!win.ws_col) {
+			char *s = getenv("COLUMNS");
+			if (s) win.ws_col = atoi(s);
+		}
+		if (win.ws_col <= 1 || win.ws_col >= 30000)
+			win.ws_col = 80;
+		*width = (int) win.ws_col;
 	}
-	if (win.ws_col <= 1) win.ws_col = 80;
-	if (height) *height = (int) win.ws_row;
-	if (width) *width = (int) win.ws_col;
 
 	return ret;
 }

Modified: trunk/busybox/networking/telnet.c
===================================================================
--- trunk/busybox/networking/telnet.c	2006-10-27 09:02:31 UTC (rev 16451)
+++ trunk/busybox/networking/telnet.c	2006-10-27 09:03:24 UTC (rev 16452)
@@ -607,7 +607,7 @@
 #endif
 
 #ifdef CONFIG_FEATURE_TELNET_TTYPE
-    ttype = getenv("TERM");
+	ttype = getenv("TERM");
 #endif
 
 	memset(&G, 0, sizeof G);

Modified: trunk/busybox/networking/wget.c
===================================================================
--- trunk/busybox/networking/wget.c	2006-10-27 09:02:31 UTC (rev 16451)
+++ trunk/busybox/networking/wget.c	2006-10-27 09:03:24 UTC (rev 16452)
@@ -676,7 +676,7 @@
 {
 	int width=0;
 	get_terminal_width_height(0, &width, NULL);
-	return (width);
+	return width;
 }
 
 static void

Modified: trunk/busybox/procps/ps.c
===================================================================
--- trunk/busybox/procps/ps.c	2006-10-27 09:02:31 UTC (rev 16451)
+++ trunk/busybox/procps/ps.c	2006-10-27 09:03:24 UTC (rev 16452)
@@ -41,7 +41,7 @@
 	/* if w is given once, GNU ps sets the width to 132,
 	 * if w is given more than once, it is "unlimited"
 	 */
-	if(w_count) {
+	if (w_count) {
 		terminal_width = (w_count==1) ? 132 : INT_MAX;
 	} else {
 		get_terminal_width_height(1, &terminal_width, NULL);
@@ -87,24 +87,24 @@
 		}
 		else
 #endif
-			if(p->rss == 0)
+			if (p->rss == 0)
 				len = printf("%5d %-8s        %s ", p->pid, p->user, p->state);
 			else
 				len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state);
 
 		i = terminal_width-len;
 
-		if(namecmd && namecmd[0]) {
-			if(i < 0)
+		if (namecmd && namecmd[0]) {
+			if (i < 0)
 				i = 0;
-			if(strlen(namecmd) > (size_t)i)
+			if (strlen(namecmd) > (size_t)i)
 				namecmd[i] = 0;
 			printf("%s\n", namecmd);
 		} else {
 			namecmd = p->short_cmd;
-			if(i < 2)
+			if (i < 2)
 				i = 2;
-			if(strlen(namecmd) > ((size_t)i-2))
+			if (strlen(namecmd) > ((size_t)i-2))
 				namecmd[i-2] = 0;
 			printf("[%s]\n", namecmd);
 		}




More information about the busybox-cvs mailing list