Skip to content

Commit 553d5b0

Browse files
yuwatabluca
authored andcommitted
ask-password: refuse empty password strv
Fixes #34270. (cherry picked from commit 623a8b1) (cherry picked from commit 34881c9)
1 parent 6c44b31 commit 553d5b0

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/shared/ask-password-api.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,16 @@ static int ask_password_keyring(const char *keyname, AskPasswordFlags flags, cha
168168
if (r < 0)
169169
return r;
170170

171-
return retrieve_key(serial, ret);
171+
_cleanup_strv_free_erase_ char **l = NULL;
172+
r = retrieve_key(serial, &l);
173+
if (r < 0)
174+
return r;
175+
176+
if (strv_isempty(l))
177+
return log_debug_errno(SYNTHETIC_ERRNO(ENOKEY), "Found an empty password from keyring.");
178+
179+
*ret = TAKE_PTR(l);
180+
return 0;
172181
}
173182

174183
static int backspace_chars(int ttyfd, size_t p) {
@@ -321,8 +330,8 @@ int ask_password_plymouth(
321330
return -ENOENT;
322331

323332
} else if (IN_SET(buffer[0], 2, 9)) {
333+
_cleanup_strv_free_erase_ char **l = NULL;
324334
uint32_t size;
325-
char **l;
326335

327336
/* One or more answers */
328337
if (p < 5)
@@ -340,15 +349,16 @@ int ask_password_plymouth(
340349
if (!l)
341350
return -ENOMEM;
342351

343-
*ret = l;
344-
break;
352+
if (strv_isempty(l))
353+
return log_debug_errno(SYNTHETIC_ERRNO(ECANCELED), "Received an empty password.");
354+
355+
*ret = TAKE_PTR(l);
356+
return 0;
345357

346358
} else
347359
/* Unknown packet */
348360
return -EIO;
349361
}
350-
351-
return 0;
352362
}
353363

354364
#define NO_ECHO "(no echo) "
@@ -944,8 +954,8 @@ int ask_password_agent(
944954

945955
static int ask_password_credential(const char *credential_name, AskPasswordFlags flags, char ***ret) {
946956
_cleanup_(erase_and_freep) char *buffer = NULL;
957+
_cleanup_strv_free_erase_ char **l = NULL;
947958
size_t size;
948-
char **l;
949959
int r;
950960

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

962-
*ret = l;
972+
if (strv_isempty(l))
973+
return log_debug_errno(SYNTHETIC_ERRNO(ENOKEY), "Found an empty password in credential.");
974+
975+
*ret = TAKE_PTR(l);
963976
return 0;
964977
}
965978

0 commit comments

Comments
 (0)