linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: perex@perex.cz, tiwai@suse.com, huangfq.daxian@gmail.com,
	tglx@linutronix.de, allison@lohutok.net
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree()
Date: Tue, 23 Jul 2019 21:40:20 +0800	[thread overview]
Message-ID: <20190723134020.25972-1-baijiaju1990@gmail.com> (raw)

In snd_gf1_mem_xfree(), there is an if statement on line 72 and line 74
to check whether block->next is NULL:
    if (block->next)

When block->next is NULL, block->next is used on line 84:
    block->next->prev = block->prev;

Thus, a possible null-pointer dereference may occur in this case.

To fix this possible bug, block->next is checked before using it.

This bug is found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 sound/isa/gus/gus_mem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/isa/gus/gus_mem.c b/sound/isa/gus/gus_mem.c
index cb02d18dde60..ed6205b88057 100644
--- a/sound/isa/gus/gus_mem.c
+++ b/sound/isa/gus/gus_mem.c
@@ -81,7 +81,8 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * blo
 		if (block->prev)
 			block->prev->next = NULL;
 	} else {
-		block->next->prev = block->prev;
+		if (block->next)
+			block->next->prev = block->prev;
 		if (block->prev)
 			block->prev->next = block->next;
 	}
-- 
2.17.0


             reply	other threads:[~2019-07-23 13:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 13:40 Jia-Ju Bai [this message]
2019-07-23 13:47 ` [PATCH] ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree() Takashi Iwai
2019-07-23 13:51   ` Jia-Ju Bai

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=20190723134020.25972-1-baijiaju1990@gmail.com \
    --to=baijiaju1990@gmail.com \
    --cc=allison@lohutok.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=huangfq.daxian@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tglx@linutronix.de \
    --cc=tiwai@suse.com \
    /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).