changeset 13289:0a79ebc0f4b3

702 tput calls gets() 703 hashmake calls gets() but should use fgets(). Reviewed by: Dan McDonald <danmcd@nexenta.com> Reviewed by: Olga Kryzhanoska <olga.kryzhanovska@gmail.com> Approved by: Garrett D'Amore <garrett@nexenta.com>
author Roland Mainz <roland.mainz@nexenta.com
date Thu, 17 Feb 2011 14:49:38 -0800
parents 8f9968bb4e4e
children 6489e7702a16
files usr/src/cmd/spell/hashmake.c usr/src/cmd/tput/tput.c
diffstat 2 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/spell/hashmake.c	Wed Feb 09 11:47:57 2011 -0500
+++ b/usr/src/cmd/spell/hashmake.c	Thu Feb 17 14:49:38 2011 -0800
@@ -26,8 +26,7 @@
 
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
+/* Copyright 2011 Nexenta Systems, Inc.  All rights reserved. */
 
 #include <stdlib.h>
 #include <unistd.h>
@@ -51,7 +50,7 @@
 	(void) textdomain(TEXT_DOMAIN);
 
 	hashinit();
-	while (gets(word)) {
+	while (fgets(word, sizeof (word), stdin)) {
 		(void) printf("%.*lo\n", (HASHWIDTH+2)/3, hash(word));
 	}
 	return (0);
--- a/usr/src/cmd/tput/tput.c	Wed Feb 09 11:47:57 2011 -0500
+++ b/usr/src/cmd/tput/tput.c	Thu Feb 17 14:49:38 2011 -0800
@@ -23,6 +23,7 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
+/* Copyright 2011 Nexenta Systems, Inc.  All rights reserved. */
 
 /*	Copyright (c) 1988 AT&T	*/
 /*	  All Rights Reserved  	*/
@@ -58,6 +59,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <locale.h>
+#include <err.h>
 
 /* externs from libcurses */
 extern int tigetnum();
@@ -166,15 +168,23 @@
 			exit(outputcap(cap, argc, argv));
 		return (0);
 	} else {			/* standard input argumets	*/
-		char buff[128];
+		char buff[256];
 		char **v;
 
-		/* allocate storage for the 'faked' argv[] array	*/
+		/*
+		 * allocate storage for the 'faked' argv[] array
+		 *
+		 * fixme: The algorithm here is botched. Who or what defines
+		 * that only 10 arguments with 32 bytes each are passed?
+		 */
 		v = (char **)malloc(10 * sizeof (char *));
-		for (i = 0; i < 10; i++)
-			v[i] = (char *)malloc(32 * sizeof (char));
+		for (i = 0; i < 10; i++) {
+			v[i] = (char *)malloc(32);
+			if (!v[i])
+				err(EXIT_FAILURE, "no memory for argv[] array");
+		}
 
-		while (gets(buff) != NULL) {
+		while (fgets(buff, sizeof (buff), stdin) != NULL) {
 			/* read standard input line; skip over empty lines */
 			if ((std_argc =
 			    sscanf(buff, "%s %s %s %s %s %s %s %s %s %s",