Skip to content

Commit

Permalink
ask-password: refuse empty password strv
Browse files Browse the repository at this point in the history
Fixes #34270.

(cherry picked from commit 623a8b1922bdbd2fb06bc5f2c67d3d6930efc58e)
(cherry picked from commit 34881c9d5afdd05e9e6f1824cbea9d1954ea80c0)
  • Loading branch information
yuwata authored and bluca committed Sep 10, 2024
1 parent 6c44b31 commit 553d5b0
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/shared/ask-password-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,16 @@ static int ask_password_keyring(const char *keyname, AskPasswordFlags flags, cha
if (r < 0)
return r;

return retrieve_key(serial, ret);
_cleanup_strv_free_erase_ char **l = NULL;
r = retrieve_key(serial, &l);
if (r < 0)
return r;

if (strv_isempty(l))
return log_debug_errno(SYNTHETIC_ERRNO(ENOKEY), "Found an empty password from keyring.");

*ret = TAKE_PTR(l);
return 0;
}

static int backspace_chars(int ttyfd, size_t p) {
Expand Down Expand Up @@ -321,8 +330,8 @@ int ask_password_plymouth(
return -ENOENT;

} else if (IN_SET(buffer[0], 2, 9)) {
_cleanup_strv_free_erase_ char **l = NULL;
uint32_t size;
char **l;

/* One or more answers */
if (p < 5)
Expand All @@ -340,15 +349,16 @@ int ask_password_plymouth(
if (!l)
return -ENOMEM;

*ret = l;
break;
if (strv_isempty(l))
return log_debug_errno(SYNTHETIC_ERRNO(ECANCELED), "Received an empty password.");

*ret = TAKE_PTR(l);
return 0;

} else
/* Unknown packet */
return -EIO;
}

return 0;
}

#define NO_ECHO "(no echo) "
Expand Down Expand Up @@ -944,8 +954,8 @@ int ask_password_agent(

static int ask_password_credential(const char *credential_name, AskPasswordFlags flags, char ***ret) {
_cleanup_(erase_and_freep) char *buffer = NULL;
_cleanup_strv_free_erase_ char **l = NULL;
size_t size;
char **l;
int r;

assert(credential_name);
Expand All @@ -959,7 +969,10 @@ static int ask_password_credential(const char *credential_name, AskPasswordFlags
if (!l)
return -ENOMEM;

*ret = l;
if (strv_isempty(l))
return log_debug_errno(SYNTHETIC_ERRNO(ENOKEY), "Found an empty password in credential.");

*ret = TAKE_PTR(l);
return 0;
}

Expand Down

0 comments on commit 553d5b0

Please sign in to comment.