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:
@@ -1492,7 +1492,7 @@ static int config_parse_routing_policy_rule_uid_range(
|
||||
|
||||
assert(rvalue);
|
||||
|
||||
if (get_user_creds(&rvalue, &p->start, NULL, NULL, NULL, 0) >= 0) {
|
||||
if (get_user_creds(rvalue, /* flags= */ 0, NULL, &p->start, NULL, NULL, NULL) >= 0) {
|
||||
p->end = p->start;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -42,13 +42,12 @@ static int run(int argc, char *argv[]) {
|
||||
/* Drop privileges, but only if we have been started as root. If we are not running as root we assume all
|
||||
* privileges are already dropped and we can't create our runtime directory. */
|
||||
if (geteuid() == 0) {
|
||||
const char *user = "systemd-network";
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
||||
r = get_user_creds(&user, &uid, &gid, NULL, NULL, 0);
|
||||
r = get_user_creds("systemd-network", /* flags= */ 0, NULL, &uid, &gid, NULL, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Cannot resolve user name %s: %m", user);
|
||||
return log_error_errno(r, "Cannot resolve user name %s: %m", "systemd-network");
|
||||
|
||||
/* Create runtime directory. This is not necessary when networkd is
|
||||
* started with "RuntimeDirectory=systemd/netif", or after
|
||||
|
||||
Reference in New Issue
Block a user