702 tput calls gets()
703 hashmake calls gets() but should use fgets().
Reviewed by: Dan McDonald <
[email protected]>
Reviewed by: Olga Kryzhanoska <
[email protected]>
Approved by: Garrett D'Amore <
[email protected]>
--- 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",