linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luca Bruno <luca.bruno@coreos.com>
To: linux-modules@vger.kernel.org
Subject: [PATCH] libkmod-module: check for NULL before accessing pointers
Date: Wed,  7 Mar 2018 10:51:21 +0000	[thread overview]
Message-ID: <20180307105121.18634-1-luca.bruno@coreos.com> (raw)

This introduces a few missing NULL-checks in public functions, and
align their docstrings with real behavior by getting rid of copy-paste
mistakes.

Signed-off-by: Luca Bruno <luca.bruno@coreos.com>
---
 TODO                     |  5 +++++
 libkmod/libkmod-module.c | 23 ++++++++++-------------
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/TODO b/TODO
index 537e7e1..3fe06eb 100644
--- a/TODO
+++ b/TODO
@@ -35,6 +35,11 @@ and libkmod
    - kmod_module_symbols_free_list()
    - kmod_module_dependency_symbols_free_list()
 
+* libkmod API breaking changes:
+   - dedicated error value for all kmod_*_get_crc() functions. Currently there
+     is no way for callers to distinguish between a valid CRC=0 and the error
+     code 0.
+
 * index: drop the "open(), seek(), read()" implementation and use another one
   with mmap(). When lookup() is called and the file is not mmaped, mmap it.
   Another possibility is to drop the mmap implementation relying on VFS to have
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 0a3ef11..ee420f4 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -2519,7 +2519,7 @@ KMOD_EXPORT const char *kmod_module_version_get_symbol(const struct kmod_list *e
 {
 	struct kmod_module_version *version;
 
-	if (entry == NULL)
+	if (entry == NULL || entry->data == NULL)
 		return NULL;
 
 	version = entry->data;
@@ -2532,14 +2532,13 @@ KMOD_EXPORT const char *kmod_module_version_get_symbol(const struct kmod_list *e
  *
  * Get the crc of a kmod module version.
  *
- * Returns: the crc of this kmod module version on success or NULL on
- * failure. The string is owned by the version, do not free it.
+ * Returns: the crc of this kmod module version if available, otherwise default to 0.
  */
 KMOD_EXPORT uint64_t kmod_module_version_get_crc(const struct kmod_list *entry)
 {
 	struct kmod_module_version *version;
 
-	if (entry == NULL)
+	if (entry == NULL || entry->data == NULL)
 		return 0;
 
 	version = entry->data;
@@ -2660,7 +2659,7 @@ KMOD_EXPORT const char *kmod_module_symbol_get_symbol(const struct kmod_list *en
 {
 	struct kmod_module_symbol *symbol;
 
-	if (entry == NULL)
+	if (entry == NULL || entry->data == NULL)
 		return NULL;
 
 	symbol = entry->data;
@@ -2673,14 +2672,13 @@ KMOD_EXPORT const char *kmod_module_symbol_get_symbol(const struct kmod_list *en
  *
  * Get the crc of a kmod module symbol.
  *
- * Returns: the crc of this kmod module symbol on success or NULL on
- * failure. The string is owned by the symbol, do not free it.
+ * Returns: the crc of this kmod module symbol if available, otherwise default to 0.
  */
 KMOD_EXPORT uint64_t kmod_module_symbol_get_crc(const struct kmod_list *entry)
 {
 	struct kmod_module_symbol *symbol;
 
-	if (entry == NULL)
+	if (entry == NULL || entry->data == NULL)
 		return 0;
 
 	symbol = entry->data;
@@ -2806,7 +2804,7 @@ KMOD_EXPORT const char *kmod_module_dependency_symbol_get_symbol(const struct km
 {
 	struct kmod_module_dependency_symbol *dependency_symbol;
 
-	if (entry == NULL)
+	if (entry == NULL || entry->data == NULL)
 		return NULL;
 
 	dependency_symbol = entry->data;
@@ -2819,14 +2817,13 @@ KMOD_EXPORT const char *kmod_module_dependency_symbol_get_symbol(const struct km
  *
  * Get the crc of a kmod module dependency_symbol.
  *
- * Returns: the crc of this kmod module dependency_symbol on success or NULL on
- * failure. The string is owned by the dependency_symbol, do not free it.
+ * Returns: the crc of this kmod module dependency_symbol if available, otherwise default to 0.
  */
 KMOD_EXPORT uint64_t kmod_module_dependency_symbol_get_crc(const struct kmod_list *entry)
 {
 	struct kmod_module_dependency_symbol *dependency_symbol;
 
-	if (entry == NULL)
+	if (entry == NULL || entry->data == NULL)
 		return 0;
 
 	dependency_symbol = entry->data;
@@ -2846,7 +2843,7 @@ KMOD_EXPORT int kmod_module_dependency_symbol_get_bind(const struct kmod_list *e
 {
 	struct kmod_module_dependency_symbol *dependency_symbol;
 
-	if (entry == NULL)
+	if (entry == NULL || entry->data == NULL)
 		return 0;
 
 	dependency_symbol = entry->data;
-- 
2.16.1


             reply	other threads:[~2018-03-07 11:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 10:51 Luca Bruno [this message]
2018-04-05 21:55 ` [PATCH] libkmod-module: check for NULL before accessing pointers Lucas De Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180307105121.18634-1-luca.bruno@coreos.com \
    --to=luca.bruno@coreos.com \
    --cc=linux-modules@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).