From ad4d1ae5654a8954f462cd2833d77c4a66b76391 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Sun, 4 Dec 2011 13:14:11 -0200 Subject: [PATCH] kmod_module_get_module: safety against NULL pointers --- libkmod/libkmod-module.c | 7 ++++--- libkmod/libkmod.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 9c679cb..8bc644f 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -270,10 +270,11 @@ KMOD_EXPORT struct kmod_list *kmod_module_get_dependency(const struct kmod_modul return mod->dep; } -KMOD_EXPORT struct kmod_module *kmod_module_get_module(const struct kmod_list *l) +KMOD_EXPORT struct kmod_module *kmod_module_get_module(const struct kmod_list *entry) { - struct kmod_module *mod = l->data; - return kmod_module_ref(mod); + if (entry == NULL) + return NULL; + return kmod_module_ref(entry->data); } KMOD_EXPORT const char *kmod_module_get_name(const struct kmod_module *mod) diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index d7687be..fca4107 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -108,7 +108,7 @@ int kmod_module_new_from_lookup(struct kmod_ctx *ctx, const char *alias, struct kmod_module *kmod_module_ref(struct kmod_module *mod); struct kmod_module *kmod_module_unref(struct kmod_module *mod); int kmod_module_unref_list(struct kmod_list *list); -struct kmod_module *kmod_module_get_module(const struct kmod_list *l); +struct kmod_module *kmod_module_get_module(const struct kmod_list *entry); struct kmod_list *kmod_module_get_dependency(const struct kmod_module *mod); int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags); -- 2.7.4