Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-6]: src/bin/rm Pull up the following revisions(s) (requested by d...
details: https://anonhg.NetBSD.org/src/rev/b3d3e895a9f2
branches: netbsd-6
changeset: 774233:b3d3e895a9f2
user: sborrill <sborrill%NetBSD.org@localhost>
date: Fri Jun 15 10:00:05 2012 +0000
description:
Pull up the following revisions(s) (requested by dholland in ticket #346):
bin/rm/rm.c: revision 1.52
Rectify race condition in rm -P processing by checking that the file
we opened is the one we expected to get. Also use O_NOFOLLOW to help
avoid even opening devices, which sometimes produce side effects.
diffstat:
bin/rm/rm.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diffs (47 lines):
diff -r fe8f68981c33 -r b3d3e895a9f2 bin/rm/rm.c
--- a/bin/rm/rm.c Fri Jun 15 08:54:01 2012 +0000
+++ b/bin/rm/rm.c Fri Jun 15 10:00:05 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rm.c,v 1.51 2012/01/21 16:38:41 christos Exp $ */
+/* $NetBSD: rm.c,v 1.51.2.1 2012/06/15 10:00:05 sborrill Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994, 2003
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)rm.c 8.8 (Berkeley) 4/27/95";
#else
-__RCSID("$NetBSD: rm.c,v 1.51 2012/01/21 16:38:41 christos Exp $");
+__RCSID("$NetBSD: rm.c,v 1.51.2.1 2012/06/15 10:00:05 sborrill Exp $");
#endif
#endif /* not lint */
@@ -380,7 +380,7 @@
static int
rm_overwrite(char *file, struct stat *sbp)
{
- struct stat sb;
+ struct stat sb, sb2;
int fd, randint;
char randchar;
@@ -394,8 +394,18 @@
return 0;
/* flags to try to defeat hidden caching by forcing seeks */
- if ((fd = open(file, O_RDWR|O_SYNC|O_RSYNC, 0)) == -1)
+ if ((fd = open(file, O_RDWR|O_SYNC|O_RSYNC|O_NOFOLLOW, 0)) == -1)
+ goto err;
+
+ if (fstat(fd, &sb2)) {
goto err;
+ }
+
+ if (sb2.st_dev != sbp->st_dev || sb2.st_ino != sbp->st_ino ||
+ !S_ISREG(sb2.st_mode)) {
+ errno = EPERM;
+ goto err;
+ }
#define RAND_BYTES 1
#define THIS_BYTE 0
Home |
Main Index |
Thread Index |
Old Index