All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian Göttsche" <cgzones@googlemail.com>
To: selinux@vger.kernel.org
Subject: [PATCH 19/25] libselinux: label_file::init(): do not pass NULL to strdup
Date: Mon,  3 May 2021 19:53:44 +0200	[thread overview]
Message-ID: <20210503175350.55954-20-cgzones@googlemail.com> (raw)
In-Reply-To: <20210503175350.55954-1-cgzones@googlemail.com>

If any of the build flags `BUILD_HOST` or `ANDROID` is set and the
caller did not pass an option of type `SELABEL_OPT_PATH`, the variable
`path` might be not set.
Add a check to avoid calling `strdup()` with a NULL pointer.

Found by cppcheck.

src/label_file.c:759:26: warning: Possible null pointer dereference: path [nullPointer]
 rec->spec_file = strdup(path);
                         ^
src/label_file.c:713:21: note: Assignment 'path=NULL', assigned value is 0
 const char *path = NULL;
                    ^
src/label_file.c:759:26: note: Null pointer dereference
 rec->spec_file = strdup(path);
                         ^

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/src/label_file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
index 4d4e3a76..39a56133 100644
--- a/libselinux/src/label_file.c
+++ b/libselinux/src/label_file.c
@@ -756,6 +756,10 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
 	}
 
 #endif
+
+	if (!path)
+		goto finish;
+
 	rec->spec_file = strdup(path);
 
 	/*
-- 
2.31.1


  parent reply	other threads:[~2021-05-03 17:54 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 17:53 [PATCH 00/25] libselinux: misc compiler and static analyzer findings Christian Göttsche
2021-05-03 17:53 ` [PATCH 01/25] libselinux: sidtab_hash(): do not discard const qualifier Christian Göttsche
2021-05-03 17:53 ` [PATCH 02/25] libselinux: selinux_file_context_cmp(): " Christian Göttsche
2021-05-03 17:53 ` [PATCH 03/25] libselinux: label_common(): " Christian Göttsche
2021-05-03 17:53 ` [PATCH 04/25] libselinux: Sha1Finalise(): " Christian Göttsche
2021-05-03 17:53 ` [PATCH 05/25] libselinux: sefcontext_compile: mark local variable static Christian Göttsche
2021-05-03 17:53 ` [PATCH 06/25] libselinux: avcstat: use standard length modifier for unsigned long long Christian Göttsche
2021-05-03 17:53 ` [PATCH 07/25] libselinux: selinux_restorecon: mark local variable static Christian Göttsche
2021-05-03 17:53 ` [PATCH 08/25] libselinux: selabel_get_digests_all_partial_matches: free memory after FTS_D block Christian Göttsche
2021-05-03 17:53 ` [PATCH 09/25] libselinux: getconlist: free memory on multiple level arguments Christian Göttsche
2021-05-03 17:53 ` [PATCH 10/25] libselinux: exclude_non_seclabel_mounts(): drop unused variable Christian Göttsche
2021-05-03 17:53 ` [PATCH 11/25] libselinux: context_new(): drop dead assignment Christian Göttsche
2021-05-03 17:53 ` [PATCH 12/25] libselinux: label_x::init(): " Christian Göttsche
2021-05-03 17:53 ` [PATCH 13/25] libselinux: label_media::init(): " Christian Göttsche
2021-05-03 17:53 ` [PATCH 14/25] libselinux: setexecfilecon(): " Christian Göttsche
2021-05-03 17:53 ` [PATCH 15/25] libselinux: getdefaultcon: free memory on multiple same arguments Christian Göttsche
2021-05-03 17:53 ` [PATCH 16/25] libselinux: store_stem(): do not free possible non-heap object Christian Göttsche
2021-05-03 17:53 ` [PATCH 17/25] libselinux: matchmediacon(): close file on error Christian Göttsche
2021-05-03 17:53 ` [PATCH 18/25] libselinux: init_selinux_config(): free resources " Christian Göttsche
2021-05-03 17:53 ` Christian Göttsche [this message]
2021-05-03 17:53 ` [PATCH 20/25] libselinux: matchpathcon: free memory on realloc failure Christian Göttsche
2021-05-03 17:53 ` [PATCH 21/25] libselinux: label_db::db_init(): open file with CLOEXEC mode Christian Göttsche
2021-05-03 17:53 ` [PATCH 22/25] libselinux: drop redundant casts to the same type Christian Göttsche
2021-05-03 17:53 ` [PATCH 23/25] libselinux: sidtab_sid_stats(): unify parameter name Christian Göttsche
2021-05-03 17:53 ` [PATCH 24/25] libselinux: regex: unify parameter names Christian Göttsche
2021-05-03 17:53 ` [PATCH 25/25] libselinux: label_file.c: fix indent Christian Göttsche
2021-05-18 18:37 ` [PATCH 00/25] libselinux: misc compiler and static analyzer findings Petr Lautrbach

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=20210503175350.55954-20-cgzones@googlemail.com \
    --to=cgzones@googlemail.com \
    --cc=selinux@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.