From 2e7cfe82f84818cd7672374db3d41dc7f1969884 Mon Sep 17 00:00:00 2001 From: englebass Date: Sat, 17 Apr 2010 18:39:13 +0000 Subject: [PATCH] efreet: Check return value from opendir git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/efreet@48081 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/efreet_desktop_cache_create.c | 1 + src/lib/efreet_menu.c | 117 +++++++++++++++++----------------- 2 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/bin/efreet_desktop_cache_create.c b/src/bin/efreet_desktop_cache_create.c index 9f07d59..6299a63 100644 --- a/src/bin/efreet_desktop_cache_create.c +++ b/src/bin/efreet_desktop_cache_create.c @@ -141,6 +141,7 @@ cache_scan(const char *path, const char *base_id, int priority, int recurse, int if (!ecore_file_is_dir(path)) return 1; files = opendir(path); + if (!files) return 1; id[0] = '\0'; while ((file = readdir(files))) { diff --git a/src/lib/efreet_menu.c b/src/lib/efreet_menu.c index 0c46b88..a80a12b 100644 --- a/src/lib/efreet_menu.c +++ b/src/lib/efreet_menu.c @@ -1928,80 +1928,83 @@ efreet_menu_handle_legacy_dir_helper(Efreet_Menu_Internal *root, path_len = strlen(path); files = opendir(path); - while ((file = readdir(files))) + if (files) { - Efreet_Desktop *desktop = NULL; - char buf[PATH_MAX]; - char *exten; + while ((file = readdir(files))) + { + Efreet_Desktop *desktop = NULL; + char buf[PATH_MAX]; + char *exten; + + if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue; + file_path[0] = '\0'; + eina_strlcpy(file_path, path, PATH_MAX); + eina_strlcpy(file_path + path_len, "/", PATH_MAX - path_len); + eina_strlcpy(file_path + path_len + 1, file->d_name, PATH_MAX - path_len - 1); + + /* recurse into sub directories */ + if (ecore_file_is_dir(file_path)) + { + Efreet_Menu_Internal *ret; - if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue; - file_path[0] = '\0'; - eina_strlcpy(file_path, path, PATH_MAX); - eina_strlcpy(file_path + path_len, "/", PATH_MAX - path_len); - eina_strlcpy(file_path + path_len + 1, file->d_name, PATH_MAX - path_len - 1); + ret = efreet_menu_handle_legacy_dir_helper(root ? root : legacy_internal, + legacy_internal, file_path, prefix); + if (!ret) + { + efreet_menu_internal_free(legacy_internal); + eina_stringshare_del(path); + closedir(files); + return NULL; + } - /* recurse into sub directories */ - if (ecore_file_is_dir(file_path)) - { - Efreet_Menu_Internal *ret; + efreet_menu_create_sub_menu_list(legacy_internal); + legacy_internal->sub_menus = eina_list_prepend(legacy_internal->sub_menus, ret); - ret = efreet_menu_handle_legacy_dir_helper(root ? root : legacy_internal, - legacy_internal, file_path, prefix); - if (!ret) + continue; + } + + if (!strcmp(file->d_name, ".directory")) { - efreet_menu_internal_free(legacy_internal); - eina_stringshare_del(path); - closedir(files); - return NULL; + legacy_internal->directory = efreet_desktop_get(file_path); + if (legacy_internal->directory + && legacy_internal->directory->type != EFREET_DESKTOP_TYPE_DIRECTORY) + { + efreet_desktop_free(legacy_internal->directory); + legacy_internal->directory = NULL; + } + continue; } - efreet_menu_create_sub_menu_list(legacy_internal); - legacy_internal->sub_menus = eina_list_prepend(legacy_internal->sub_menus, ret); + exten = strrchr(file->d_name, '.'); - continue; - } + if (exten && !strcmp(exten, ".desktop")) + desktop = efreet_desktop_get(file_path); - if (!strcmp(file->d_name, ".directory")) - { - legacy_internal->directory = efreet_desktop_get(file_path); - if (legacy_internal->directory - && legacy_internal->directory->type != EFREET_DESKTOP_TYPE_DIRECTORY) + if (!desktop) continue; + + /* if the .desktop has categories it isn't legacy */ + if (efreet_desktop_category_count_get(desktop) != 0) { - efreet_desktop_free(legacy_internal->directory); - legacy_internal->directory = NULL; + efreet_desktop_free(desktop); + continue; } - continue; - } - - exten = strrchr(file->d_name, '.'); - if (exten && !strcmp(exten, ".desktop")) - desktop = efreet_desktop_get(file_path); + /* XXX: This will disappear when the .desktop is free'd */ + efreet_desktop_category_add(desktop, "Legacy"); - if (!desktop) continue; + if (prefix) + { + snprintf(buf, sizeof(buf), "%s%s", prefix, file->d_name); + filter->op->filenames = eina_list_append(filter->op->filenames, eina_stringshare_add(buf)); + } + else + filter->op->filenames = eina_list_append(filter->op->filenames, eina_stringshare_add(file->d_name)); - /* if the .desktop has categories it isn't legacy */ - if (efreet_desktop_category_count_get(desktop) != 0) - { + count++; efreet_desktop_free(desktop); - continue; - } - - /* XXX: This will disappear when the .desktop is free'd */ - efreet_desktop_category_add(desktop, "Legacy"); - - if (prefix) - { - snprintf(buf, sizeof(buf), "%s%s", prefix, file->d_name); - filter->op->filenames = eina_list_append(filter->op->filenames, eina_stringshare_add(buf)); } - else - filter->op->filenames = eina_list_append(filter->op->filenames, eina_stringshare_add(file->d_name)); - - count++; - efreet_desktop_free(desktop); + closedir(files); } - closedir(files); eina_stringshare_del(path); return legacy_internal; -- 2.7.4