From 61848aadd74476cc6f77abb18def9cd4219d9b53 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 14 Feb 2025 18:39:58 +0000 Subject: [PATCH] io: fix null pointer deref in win32 update_iterator_data --- io/sys/windows/directory.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/io/sys/windows/directory.c b/io/sys/windows/directory.c index 6fbb881..7b2e1f8 100644 --- a/io/sys/windows/directory.c +++ b/io/sys/windows/directory.c @@ -159,17 +159,18 @@ static void update_iterator_data(struct b_directory_iterator *it) } struct iteration_state *state = get_iteration_state(it->_z); - it->filename = state->data.cFileName; + if (state) { + it->filename = state->data.cFileName; - struct b_path *filename = b_path_create_from_cstr(it->filename); + struct b_path *filename = b_path_create_from_cstr(it->filename); - const struct b_path *parts[] = { - state->search_path, - filename, - }; + const struct b_path *parts[] = { + state->search_path, + filename, + }; - it->filepath - = b_path_join(parts, sizeof parts / sizeof parts[0]); + it->filepath = b_path_join(parts, sizeof parts / sizeof parts[0]); + } } static bool move_into_directory(struct b_directory_iterator *it, const char *dir_name)