Module Name:    src
Committed By:   snj
Date:           Fri Dec 18 06:06:56 UTC 2009

Modified Files:
        src/usr.bin/less/less [netbsd-5]: cmdbuf.c

Log Message:
Pull up following revision(s) (requested by dholland in ticket #1194):
        usr.bin/less/less/cmdbuf.c: revision 1.8
Don't attempt to read or write ~/.lesshst if it's not a regular file
or a symlink to a regular file. Previously, symlinking to /dev/null
would cause less to trash /dev/null if run with sufficient privileges,
as seen in PR misc/42237.
While the official way to disable .lesshst is to set an environment
variable, that is problematic in some cases, such as single-user mode.
A safer way to prevent even an unpatched less from writing anything
out is to mkdir ~/.lesshst.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.7.24.1 src/usr.bin/less/less/cmdbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/less/less/cmdbuf.c
diff -u src/usr.bin/less/less/cmdbuf.c:1.7 src/usr.bin/less/less/cmdbuf.c:1.7.24.1
--- src/usr.bin/less/less/cmdbuf.c:1.7	Thu Oct 26 01:33:08 2006
+++ src/usr.bin/less/less/cmdbuf.c	Fri Dec 18 06:06:56 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmdbuf.c,v 1.7 2006/10/26 01:33:08 mrg Exp $	*/
+/*	$NetBSD: cmdbuf.c,v 1.7.24.1 2009/12/18 06:06:56 snj Exp $	*/
 
 /*
  * Copyright (C) 1984-2005  Mark Nudelman
@@ -22,6 +22,9 @@
 #if HAVE_STAT
 #include <sys/stat.h>
 #endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
 
 extern int sc_width;
 extern int utf_mode;
@@ -1362,10 +1365,20 @@
 	char *filename;
 	FILE *f;
 	char *p;
+#ifdef HAVE_STAT
+	struct stat st;
+#endif
 
 	filename = histfile_name();
 	if (filename == NULL)
 		return;
+#ifdef HAVE_STAT
+	/* ignore devices/fifos; allow symlinks */
+	if (stat(filename, &st) < 0)
+		return;
+	if (!S_ISREG(st.st_mode))
+		return;
+#endif
 	f = fopen(filename, "r");
 	free(filename);
 	if (f == NULL)
@@ -1442,10 +1455,22 @@
 #if CMD_HISTORY
 	char *filename;
 	FILE *f;
+#ifdef HAVE_STAT
+	struct stat st;
+#endif
 
 	filename = histfile_name();
 	if (filename == NULL)
 		return;
+#ifdef HAVE_STAT
+	/* ignore devices/fifos; allow symlinks */
+	if (stat(filename, &st) < 0) {
+		if (errno != ENOENT)
+			return;
+	}
+	else if (!S_ISREG(st.st_mode))
+		return;
+#endif
 	f = fopen(filename, "w");
 	free(filename);
 	if (f == NULL)

Reply via email to