env-util: replace unsetenv_erase() by new getenv_steal_erase() helper
The new helper combines a bunch of steps every invocation of unsetenv_erase() did so far: getenv() + strdup() + unsetenv_erase(). Let's unify this into one helper that is harder to use incorrectly. It's in inspired by TAKE_PTR() in a way: get the env var out and invalidate where it was before.
This commit is contained in:
committed by
Yu Watanabe
parent
5cf84d2545
commit
e99ca14741
@@ -275,15 +275,17 @@ int pkcs11_token_login(
|
||||
|
||||
for (unsigned tries = 0; tries < 3; tries++) {
|
||||
_cleanup_strv_free_erase_ char **passwords = NULL;
|
||||
char **i, *e;
|
||||
_cleanup_(erase_and_freep) char *envpin = NULL;
|
||||
char **i;
|
||||
|
||||
e = getenv("PIN");
|
||||
if (e) {
|
||||
passwords = strv_new(e);
|
||||
r = getenv_steal_erase("PIN", &envpin);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to acquire PIN from environment: %m");
|
||||
if (r > 0) {
|
||||
passwords = strv_new(envpin);
|
||||
if (!passwords)
|
||||
return log_oom();
|
||||
|
||||
assert_se(unsetenv_erase("PIN") >= 0);
|
||||
} else if (headless)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENOPKG), "PIN querying disabled via 'headless' option. Use the 'PIN' environment variable.");
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user