From 3a0f6c217d178ff97c0fb7182604f852569be580 Mon Sep 17 00:00:00 2001
From: Mike Yuan <me@yhndnzj.com>
Date: Tue, 6 Feb 2024 22:17:34 +0800
Subject: [PATCH] core/exec-credential: add missing assertions
src/core/exec-credential.c | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
@@ -172,6 +172,10 @@ static int write_credential(
_cleanup_close_ int fd = -EBADF;
int r;
+ assert(dfd >= 0);
+ assert(id);
+ assert(data || size == 0);
+
r = tempfn_random_child("", "cred", &tmp);
if (r < 0)
return r;
@@ -224,7 +228,6 @@ typedef enum CredentialSearchPath {
} CredentialSearchPath;
static char **credential_search_path(const ExecParameters *params, CredentialSearchPath path) {
-
_cleanup_strv_free_ char **l = NULL;
assert(params);
@@ -275,6 +278,10 @@ static int maybe_decrypt_and_write_credential(
size_t add;
int r;
+ assert(dir_fd >= 0);
+ assert(id);
+ assert(left);
+
if (encrypted) {
size_t plaintext_size = 0;
@@ -302,7 +309,7 @@ static int maybe_decrypt_and_write_credential(
static int load_credential_glob(
const char *path,
bool encrypted,
- char **search_path,
+ char * const *search_path,
ReadFullFileFlags flags,
int write_dfd,
uid_t uid,
@@ -312,6 +319,11 @@ static int load_credential_glob(
int r;
+ assert(path);
+ assert(search_path);
+ assert(write_dfd >= 0);
+ assert(left);
+
STRV_FOREACH(d, search_path) {
_cleanup_globfree_ glob_t pglob = {};
_cleanup_free_ char *j = NULL;
@@ -518,6 +530,9 @@ static int load_cred_recurse_dir_cb(
_cleanup_free_ char *sub_id = NULL;
int r;
+ assert(path);
+ assert(de);
+
if (event != RECURSE_DIR_ENTRY)
return RECURSE_DIR_CONTINUE;
@@ -574,6 +589,8 @@ static int acquire_credentials(
int r;
assert(context);
+ assert(params);
+ assert(unit);
assert(p);
dfd = open(p, O_DIRECTORY|O_CLOEXEC);
@@ -618,8 +635,7 @@ static int acquire_credentials(
&left);
else
/* Directory */
- r = recurse_dir(
- sub_fd,
+ r = recurse_dir(sub_fd,
/* path= */ lc->id, /* recurse_dir() will suffix the subdir paths from here to the top-level id */
/* statx_mask= */ 0,
/* n_depth_max= */ UINT_MAX,
@@ -760,6 +776,8 @@ static int setup_credentials_internal(
const char *where;
assert(context);
+ assert(params);
+ assert(unit);
assert(final);
assert(workspace);
@@ -905,6 +923,7 @@ int exec_setup_credentials(
assert(context);
assert(params);
+ assert(unit);
if (!exec_context_has_credentials(context))
return 0;
--
2.43.0