summaryrefslogtreecommitdiff
path: root/bin/rm
diff options
context:
space:
mode:
Diffstat (limited to 'bin/rm')
-rw-r--r--bin/rm/rm.16
-rw-r--r--bin/rm/rm.c11
2 files changed, 13 insertions, 4 deletions
diff --git a/bin/rm/rm.1 b/bin/rm/rm.1
index d04e4873272..5c8aefaab7d 100644
--- a/bin/rm/rm.1
+++ b/bin/rm/rm.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: rm.1,v 1.39 2015/10/13 04:30:53 daniel Exp $
+.\" $OpenBSD: rm.1,v 1.40 2016/04/15 23:09:57 tedu Exp $
.\" $NetBSD: rm.1,v 1.8 1995/07/25 19:37:30 jtc Exp $
.\"
.\" Copyright (c) 1990, 1993, 1994
@@ -33,7 +33,7 @@
.\"
.\" @(#)rm.1 8.5 (Berkeley) 12/5/94
.\"
-.Dd $Mdocdate: October 13 2015 $
+.Dd $Mdocdate: April 15 2016 $
.Dt RM 1
.Os
.Sh NAME
@@ -101,7 +101,7 @@ The
.Nm
utility removes symbolic links, not the files referenced by the links.
.Pp
-It is an error to attempt to remove the files
+It is an error to attempt to remove the root directory or the files
.Dq \&.
or
.Dq .. .
diff --git a/bin/rm/rm.c b/bin/rm/rm.c
index f9c19549d5f..2f919ffad9c 100644
--- a/bin/rm/rm.c
+++ b/bin/rm/rm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rm.c,v 1.36 2016/02/01 22:34:19 gsoares Exp $ */
+/* $OpenBSD: rm.c,v 1.37 2016/04/15 23:09:57 tedu Exp $ */
/* $NetBSD: rm.c,v 1.19 1995/09/07 06:48:50 jtc Exp $ */
/*-
@@ -395,9 +395,17 @@ checkdot(char **argv)
{
char *p, **save, **t;
int complained;
+ struct stat sb, root;
+ stat("/", &root);
complained = 0;
for (t = argv; *t;) {
+ if (lstat(*t, &sb) == 0 &&
+ root.st_ino == sb.st_ino && root.st_dev == sb.st_dev) {
+ if (!complained++)
+ warnx("\"/\" may not be removed");
+ goto skip;
+ }
/* strip trailing slashes */
p = strrchr(*t, '\0');
while (--p > *t && *p == '/')
@@ -412,6 +420,7 @@ checkdot(char **argv)
if (ISDOT(p)) {
if (!complained++)
warnx("\".\" and \"..\" may not be removed");
+skip:
eval = 1;
for (save = t; (t[0] = t[1]) != NULL; ++t)
continue;