Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crashes on /proc/ish from CLI build #2386

Merged
merged 1 commit into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions fs/proc/ish.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ static int proc_ish_show_colors(struct proc_entry *UNUSED(entry), struct proc_da
}

static int proc_ish_show_documents(struct proc_entry *UNUSED(entry), struct proc_data *buf) {
if (get_documents_directory == NULL) {
proc_printf(buf, "\n");
return 0;
}
char *directory = get_documents_directory();
proc_printf(buf, "%s\n", directory);
free(directory);
Expand All @@ -75,21 +79,21 @@ static int proc_ish_defaults_readlink(struct proc_entry *entry, char *buf) {
static int proc_ish_underlying_defaults_show(struct proc_entry *entry, struct proc_data *data) {
size_t size;
char *buffer;
if (!get_user_default(entry->name, &buffer, &size))
if (get_user_default == NULL || !get_user_default(entry->name, &buffer, &size))
return _EIO;
proc_buf_append(data, buffer, size);
free(buffer);
return 0;
}

static int proc_ish_underlying_defaults_update(struct proc_entry *entry, struct proc_data *data) {
if (!set_user_default(entry->name, data->data, data->size))
if (set_user_default == NULL || !set_user_default(entry->name, data->data, data->size))
return _EIO;
return 0;
}

static int proc_ish_underlying_defaults_unlink(struct proc_entry *entry) {
return remove_user_default(entry->name) ? 0 : _EIO;
return (remove_user_default != NULL && remove_user_default(entry->name)) ? 0 : _EIO;
}

static int proc_ish_defaults_unlink(struct proc_entry *entry) {
Expand All @@ -115,13 +119,17 @@ static void get_child_names(struct proc_entry *entry, unsigned long index) {
if (index == 0 || entry->child_names == NULL) {
if (entry->child_names != NULL)
free_string_array(entry->child_names);
entry->child_names = get_all_defaults_keys();
if (get_all_defaults_keys == NULL) {
entry->child_names = NULL;
} else {
entry->child_names = get_all_defaults_keys();
}
}
}

static bool proc_ish_underlying_defaults_readdir(struct proc_entry *entry, unsigned long *index, struct proc_entry *next_entry) {
get_child_names(entry, *index);
if (entry->child_names[*index] == NULL)
if (entry->child_names == NULL || entry->child_names[*index] == NULL)
return false;
next_entry->meta = &proc_ish_underlying_defaults_fd;
next_entry->name = strdup(entry->child_names[*index]);
Expand All @@ -133,7 +141,10 @@ static bool proc_ish_defaults_readdir(struct proc_entry *entry, unsigned long *i
get_child_names(entry, *index);
char *friendly_name;
do {
const char *name = entry->child_names[*index];
const char *name = NULL;
if (entry->child_names != NULL) {
name = entry->child_names[*index];
}
if (name == NULL)
return false;
friendly_name = get_friendly_name(name);
Expand Down
Loading