]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: initialize row/column explicitly before calling sd_json_parse_file()
authorLennart Poettering <lennart@poettering.net>
Thu, 20 Feb 2025 09:04:34 +0000 (10:04 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 20 Feb 2025 16:34:36 +0000 (17:34 +0100)
The variables are error return parameters, i.e. only initialized on some errors,
not all. Let's hence always zero initialize them.

src/analyze/analyze-security.c
src/home/homectl.c
src/home/homed-home.c
src/home/homed-manager.c
src/home/homework-luks.c
src/home/homework.c
src/network/networkd-serialize.c
src/varlinkctl/varlinkctl.c

index b6e486ffb1ff9fb017301d434e8799c32c8b1ea0..11825832de0c1ebf8a2702e5be64f6f824a8cc10 100644 (file)
@@ -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)
index b2a7bc6c107a07e3b515e6d9bf1106bef1518ba2..c398b324fdd8e9ba00226e71b309e94ac6f73d82 100644 (file)
@@ -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(
index a2c28337f496069aadf45f88e6ba997018a5eae1..eba7be9b6a5b0c75ca4d85bfaee8e2315b1a0dd1 100644 (file)
@@ -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);
index 447d8949cca7e7faa2b63cc04833fb182e95d124..62a1a636f853bccff864dd9cc04d46f4763d6d9b 100644 (file)
@@ -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);
index 4b73bd779d6a2ea5660894a037508b847efa2a42..9723d8511f47e35756a58e974c4d025d57547836 100644 (file)
@@ -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);
index 9d3eb94ab2b6a608b858a090fa810bf6f8f89d2f..404782325462e1aecd346a90ce0900f3193f5ff4 100644 (file)
@@ -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);
index 6e9536e1827ef42a5bde839b0fa28868b019b102..78c13b81c157aba3cedd92fbe939fd68a0f316e1 100644 (file)
@@ -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,
index 76c9e4850a710e2dca96a0681f332fcf4e72714c..cecd6c90df819a045424c4013e89439ca756a6b6 100644 (file)
@@ -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 = "<argv[4]>";