From bd1ea38423231d7735f648d80db0016ec2ba760e Mon Sep 17 00:00:00 2001 From: Hadi Chokr Date: Tue, 28 Apr 2026 12:18:43 +0200 Subject: [PATCH] useradd: fix btrfs subvolume creation for single-component basedir dirname() replaces broken stpcpy index arithmetic that produced an empty string for single-component paths (e.g. /koolhome), causing statfs to fail and fall back to a regular directory. Use path in the error message since dirname() modifies btrfs_check in-place, making it unusable for logging after the call. Fixes: c1d36a8acb1d (2019-05-04; "Add support for btrfs subvolumes for user homes") Signed-off-by: Hadi Chokr Reviewed-by: Alejandro Colomar --- src/useradd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/useradd.c b/src/useradd.c index 9210379c8..c0e28ef8b 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -2274,10 +2274,9 @@ static void create_home(const struct option_flags *flags) Prog, path); fail_exit(E_HOMEDIR, process_selinux); } - stpcpy(&btrfs_check[strlen(path) - strlen(cp) - 1], ""); - if (statfs(btrfs_check, &sfs) == -1) { - fprintf(stderr, "%s: statfs(\"%s\"): %s\n", - Prog, btrfs_check, strerrno()); + if (statfs(dirname(btrfs_check), &sfs) == -1) { + fprintf(stderr, "%s: statfs(dirname(\"%s\")): %s\n", + Prog, path, strerrno()); fail_exit(E_HOMEDIR, process_selinux); } free(btrfs_check); -- 2.47.3