svn commit: r303217 - in head/usr.sbin/pw: . tests

Baptiste Daroussin bapt at FreeBSD.org
Sat Jul 23 10:19:11 UTC 2016


Author: bapt
Date: Sat Jul 23 10:19:10 2016
New Revision: 303217
URL: https://svnweb.freebsd.org/changeset/base/303217

Log:
  Do not try to delete the home of the user if is is not a directory for example
  "/dev/null"
  
  PR:		211195
  Submitted by:	rday <ryan at ryanday.net>
  Reported by:	eniorm <eniorm at gmail.com>
  MFC after:	1 day

Modified:
  head/usr.sbin/pw/rm_r.c
  head/usr.sbin/pw/tests/pw_userdel.sh

Modified: head/usr.sbin/pw/rm_r.c
==============================================================================
--- head/usr.sbin/pw/rm_r.c	Sat Jul 23 08:23:57 2016	(r303216)
+++ head/usr.sbin/pw/rm_r.c	Sat Jul 23 10:19:10 2016	(r303217)
@@ -50,6 +50,9 @@ rm_r(int rootfd, const char *path, uid_t
 		path++;
 
 	dirfd = openat(rootfd, path, O_DIRECTORY);
+	if (dirfd == -1) {
+		return;
+	}
 
 	d = fdopendir(dirfd);
 	while ((e = readdir(d)) != NULL) {

Modified: head/usr.sbin/pw/tests/pw_userdel.sh
==============================================================================
--- head/usr.sbin/pw/tests/pw_userdel.sh	Sat Jul 23 08:23:57 2016	(r303216)
+++ head/usr.sbin/pw/tests/pw_userdel.sh	Sat Jul 23 10:19:10 2016	(r303217)
@@ -59,9 +59,18 @@ delete_numeric_name_body() {
 		${PW} userdel -n 4001
 }
 
+atf_test_case home_not_a_dir
+home_not_a_dir_body() {
+	populate_root_etc_skel
+	touch ${HOME}/foo
+	atf_check ${RPW} useradd foo -d /foo
+	atf_check ${RPW} userdel foo -r
+}
+
 atf_init_test_cases() {
 	atf_add_test_case rmuser_seperate_group
 	atf_add_test_case user_do_not_try_to_delete_root_if_user_unknown
 	atf_add_test_case delete_files
 	atf_add_test_case delete_numeric_name
+	atf_add_test_case home_not_a_dir
 }


More information about the svn-src-head mailing list