From: Lennart Poettering Date: Thu, 20 Feb 2025 09:04:34 +0000 (+0100) Subject: tree-wide: initialize row/column explicitly before calling sd_json_parse_file() X-Git-Tag: v258-rc1~1287 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9df18e4bee8ad4034a6fd278c1027005199b91c5;p=thirdparty%2Fsystemd.git tree-wide: initialize row/column explicitly before calling sd_json_parse_file() The variables are error return parameters, i.e. only initialized on some errors, not all. Let's hence always zero initialize them. --- diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c index b6e486ffb1f..11825832de0 100644 --- a/src/analyze/analyze-security.c +++ b/src/analyze/analyze-security.c @@ -2900,7 +2900,6 @@ int verb_security(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *policy = NULL; int r; - unsigned line, column; if (!arg_offline) { r = acquire_bus(&bus, NULL); @@ -2910,6 +2909,7 @@ int verb_security(int argc, char *argv[], void *userdata) { pager_open(arg_pager_flags); + unsigned line = 0, column = 0; if (arg_security_policy) { r = sd_json_parse_file(/*f=*/ NULL, arg_security_policy, /*flags=*/ 0, &policy, &line, &column); if (r < 0) diff --git a/src/home/homectl.c b/src/home/homectl.c index b2a7bc6c107..c398b324fdd 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -1119,7 +1119,7 @@ static int acquire_new_home_record(sd_json_variant *input, UserRecord **ret) { assert(ret); if (arg_identity) { - unsigned line, column; + unsigned line = 0, column = 0; if (input) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Two identity records specified, refusing."); @@ -1599,7 +1599,7 @@ static int acquire_updated_home_record( assert(ret); if (arg_identity) { - unsigned line, column; + unsigned line = 0, column = 0; sd_json_variant *un; r = sd_json_parse_file( diff --git a/src/home/homed-home.c b/src/home/homed-home.c index a2c28337f49..eba7be9b6a5 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -549,7 +549,6 @@ static int home_parse_worker_stdout(int _fd, UserRecord **ret) { _cleanup_close_ int fd = _fd; /* take possession, even on failure */ _cleanup_(user_record_unrefp) UserRecord *hr = NULL; _cleanup_fclose_ FILE *f = NULL; - unsigned line, column; struct stat st; int r; @@ -581,6 +580,7 @@ static int home_parse_worker_stdout(int _fd, UserRecord **ret) { rewind(f); } + unsigned line = 0, column = 0; r = sd_json_parse_file(f, "stdout", SD_JSON_PARSE_SENSITIVE, &v, &line, &column); if (r < 0) return log_error_errno(r, "Failed to parse identity at %u:%u: %m", line, column); diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 447d8949cca..62a1a636f85 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -359,7 +359,6 @@ static int manager_add_home_by_record( _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_(user_record_unrefp) UserRecord *hr = NULL; - unsigned line, column; int r, is_signed; struct stat st; Home *h; @@ -379,6 +378,7 @@ static int manager_add_home_by_record( if (st.st_size == 0) goto unlink_this_file; + unsigned line = 0, column = 0; r = sd_json_parse_file_at(NULL, dir_fd, fname, SD_JSON_PARSE_SENSITIVE, &v, &line, &column); if (r < 0) return log_error_errno(r, "Failed to parse identity record at %s:%u%u: %m", fname, line, column); diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 4b73bd779d6..9723d8511f4 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -835,7 +835,6 @@ static int luks_validate_home_record( const char *text, *type; crypt_token_info state; sd_json_variant *jr, *jiv; - unsigned line, column; const EVP_CIPHER *cc; state = sym_crypt_token_status(cd, token, &type); @@ -853,6 +852,7 @@ static int luks_validate_home_record( if (r < 0) return log_error_errno(r, "Failed to read LUKS token %i: %m", token); + unsigned line = 0, column = 0; r = sd_json_parse(text, SD_JSON_PARSE_SENSITIVE, &v, &line, &column); if (r < 0) return log_error_errno(r, "Failed to parse LUKS token JSON data %u:%u: %m", line, column); diff --git a/src/home/homework.c b/src/home/homework.c index 9d3eb94ab2b..40478232546 100644 --- a/src/home/homework.c +++ b/src/home/homework.c @@ -542,7 +542,6 @@ int home_sync_and_statfs(int root_fd, struct statfs *ret) { static int read_identity_file(int root_fd, sd_json_variant **ret) { _cleanup_fclose_ FILE *identity_file = NULL; _cleanup_close_ int identity_fd = -EBADF; - unsigned line, column; int r; assert(root_fd >= 0); @@ -560,6 +559,7 @@ static int read_identity_file(int root_fd, sd_json_variant **ret) { if (!identity_file) return log_oom(); + unsigned line = 0, column = 0; r = sd_json_parse_file(identity_file, ".identity", SD_JSON_PARSE_SENSITIVE, ret, &line, &column); if (r < 0) return log_error_errno(r, "[.identity:%u:%u] Failed to parse JSON data: %m", line, column); @@ -1981,7 +1981,6 @@ static int run(int argc, char *argv[]) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_fclose_ FILE *opened_file = NULL; _cleanup_hashmap_free_ Hashmap *blobs = NULL; - unsigned line = 0, column = 0; const char *json_path = NULL, *blob_filename; FILE *json_file; usec_t start; @@ -2012,6 +2011,7 @@ static int run(int argc, char *argv[]) { json_file = stdin; } + unsigned line = 0, column = 0; r = sd_json_parse_file(json_file, json_path, SD_JSON_PARSE_SENSITIVE, &v, &line, &column); if (r < 0) return log_error_errno(r, "[%s:%u:%u] Failed to parse JSON data: %m", json_path, line, column); diff --git a/src/network/networkd-serialize.c b/src/network/networkd-serialize.c index 6e9536e1827..78c13b81c15 100644 --- a/src/network/networkd-serialize.c +++ b/src/network/networkd-serialize.c @@ -442,7 +442,7 @@ int manager_deserialize(Manager *manager) { return log_debug_errno(errno, "Failed to fdopen() serialization file descriptor: %m"); _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; - unsigned err_line, err_column; + unsigned err_line = 0, err_column = 0; r = sd_json_parse_file( f, /* path = */ NULL, diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c index 76c9e4850a7..cecd6c90df8 100644 --- a/src/varlinkctl/varlinkctl.c +++ b/src/varlinkctl/varlinkctl.c @@ -529,7 +529,6 @@ static int verb_call(int argc, char *argv[], void *userdata) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *jp = NULL; _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL; const char *url, *method, *parameter, *source; - unsigned line = 0, column = 0; int r; assert(argc >= 3); @@ -551,6 +550,7 @@ static int verb_call(int argc, char *argv[], void *userdata) { if (!varlink_idl_qualified_symbol_name_is_valid(method)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not a valid qualified method name: '%s' (Expected valid Varlink interface name, followed by a dot, followed by a valid Varlink symbol name.)", method); + unsigned line = 0, column = 0; if (parameter) { source = "";