ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree()
PATCH 1/1 ALSA: isa: gus: Fix a possible null-pointer dereference in snd_gf1_mem_xfree()
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.
--- sound/isa/gus/gus_mem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/isa/gus/gus_mem.c +2 -1
@@ -81,7 +81,8 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * bloif (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; }
Signature · 1 line
2.17.0
Quoted 9 lines · Jia-Ju Bai
In
snd_gf1_mem_xfree(), there is an if statement on line 72 and line 74 to check whetherblock->nextis NULL:if (block->next)When
block->nextis NULL,block->nextis used on line 84:block->next->prev = block->prev;Thus, a possible null-pointer dereference may occur in this case.
There is already a check beforehand:
if (alloc->last == block) {and the code path you're referring to is only after this check fails, i.e. it's no last entry, hence block->next can be never NULL.
So the current code is OK.
thanks,
Takashi
Quoted 28 lines
To fix this possible bug,
block->nextis checked before using it.This bug is found by a static analysis tool STCheck written by us.
Signed-off-by Jia-Ju Bai <[email protected]>--- sound/isa/gus/gus_mem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)sound/isa/gus/gus_mem.c +2
-1@@ -81,7 +81,8 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * bloif (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; }Signature · 1 line
2.17.0
Thanks for the quick reply :)
I think you are right, and I did not consider "if (alloc->last == block)" Sorry for the false report...
Best wishes,
Jia-Ju Bai
Quoted 51 lines · Takashi Iwai
Quoted 8 lines · Jia-Ju Bai
In
snd_gf1_mem_xfree(), there is an if statement on line 72 and line 74 to check whetherblock->nextis NULL:if (block->next)When
block->nextis NULL,block->nextis used on line 84:block->next->prev = block->prev;Thus, a possible null-pointer dereference may occur in this case.
There is already a check beforehand:
if (alloc->last == block) {and the code path you're referring to is only after this check fails, i.e. it's no last entry, hence
block->nextcan be never NULL.So the current code is OK.
thanks,
Takashi
Quoted 27 lines
To fix this possible bug,
block->nextis checked before using it.This bug is found by a static analysis tool STCheck written by us.
Signed-off-by Jia-Ju Bai <[email protected]>--- sound/isa/gus/gus_mem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)sound/isa/gus/gus_mem.c +2
-1@@ -81,7 +81,8 @@ int snd_gf1_mem_xfree(struct snd_gf1_mem * alloc, struct snd_gf1_mem_block * bloif (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; }Signature · 1 line
2.17.0