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.
This commit is contained in:
Lennart Poettering
2025-02-20 10:04:34 +01:00
parent 2cf95e5178
commit 9df18e4bee
8 changed files with 10 additions and 10 deletions

View 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)

View 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(

View 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);

View 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);

View 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);

View 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);

View 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,

View 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]>";