user-util: return malloc'ed strings in get_user_creds
get_user_creds would use getpwnam() and then returns strings pointing into the static buffer. This seems very iffy. Let's duplicate the strings properly
This commit is contained in:
@@ -244,17 +244,14 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) {
|
||||
return r;
|
||||
break;
|
||||
|
||||
OPTION_LONG("owner", "USER", "Add uid= and gid= options for USER"): {
|
||||
const char *user = opts.arg;
|
||||
|
||||
r = get_user_creds(&user, &arg_uid, &arg_gid, NULL, NULL, 0);
|
||||
OPTION_LONG("owner", "USER", "Add uid= and gid= options for USER"):
|
||||
r = get_user_creds(opts.arg, /* flags= */ 0, NULL, &arg_uid, &arg_gid, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r,
|
||||
r == -EBADMSG ? "UID or GID of user %s are invalid."
|
||||
: "Cannot use \"%s\" as owner: %m",
|
||||
opts.arg);
|
||||
break;
|
||||
}
|
||||
|
||||
OPTION_LONG("fsck", "BOOL", "Run a file system check before mount"):
|
||||
r = parse_boolean_argument("--fsck=", opts.arg, &arg_fsck);
|
||||
|
||||
Reference in New Issue
Block a user