summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2016-07-23 10:19:10 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2016-07-23 10:19:10 +0000
commita74ddb4e401b4f5e6d09759cc67ab639ce8e98b9 (patch)
tree2d9bd9046e6d6ec1f968d8099aa3b66534f5d8b8
parent80285e3e194993731e573e5ffa1eba819e283ddd (diff)
downloadpw-darwin-a74ddb4e401b4f5e6d09759cc67ab639ce8e98b9.tar.gz
pw-darwin-a74ddb4e401b4f5e6d09759cc67ab639ce8e98b9.tar.zst
pw-darwin-a74ddb4e401b4f5e6d09759cc67ab639ce8e98b9.zip
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@ryanday.net> Reported by: eniorm <eniorm@gmail.com> MFC after: 1 day
-rw-r--r--pw/rm_r.c3
-rwxr-xr-xpw/tests/pw_userdel.sh9
2 files changed, 12 insertions, 0 deletions
diff --git a/pw/rm_r.c b/pw/rm_r.c
index 172c7b0..45fc5d1 100644
--- a/pw/rm_r.c
+++ b/pw/rm_r.c
@@ -50,6 +50,9 @@ rm_r(int rootfd, const char *path, uid_t uid)
path++;
dirfd = openat(rootfd, path, O_DIRECTORY);
+ if (dirfd == -1) {
+ return;
+ }
d = fdopendir(dirfd);
while ((e = readdir(d)) != NULL) {
diff --git a/pw/tests/pw_userdel.sh b/pw/tests/pw_userdel.sh
index f608029..d03501a 100755
--- a/pw/tests/pw_userdel.sh
+++ b/pw/tests/pw_userdel.sh
@@ -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
}