All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs: ext4: Fix dereferencing the null pointer 'ptr'
@ 2022-11-23  8:06 Mikhail Ilin
  2022-11-23  8:47 ` Stefan Roese
  0 siblings, 1 reply; 2+ messages in thread
From: Mikhail Ilin @ 2022-11-23  8:06 UTC (permalink / raw)
  To: u-boot; +Cc: Mikhail Ilin, Stefan Roese, Stephen Warren

 If memory allocation fails on line 780, then 'fail' will be
 jumped to and 'ptr' will be null, causing it to be dereferenced it on line
 855. Thus, before using 'ptr[i]' one must make sure that the 'ptr' pointer
 is not NULL.

Fixes: 934b14f2bb30 ("ext4: free allocations by parse_path()")
Signed-off-by: Mikhail Ilin <ilin.mikhail.ol@gmail.com>
---
 fs/ext4/ext4_common.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 1185cb2c04..3cdd1a04a9 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -851,10 +851,12 @@ end:
 fail:
 	free(depth_dirname);
 	free(parse_dirname);
-	for (i = 0; i < depth; i++) {
-		if (!ptr[i])
-			break;
-		free(ptr[i]);
+	if (ptr) {
+		for (i = 0; i < depth; i++) {
+			if (!ptr[i])
+				break;
+			free(ptr[i]);
+		}
 	}
 	free(ptr);
 	free(parent_inode);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs: ext4: Fix dereferencing the null pointer 'ptr'
  2022-11-23  8:06 [PATCH] fs: ext4: Fix dereferencing the null pointer 'ptr' Mikhail Ilin
@ 2022-11-23  8:47 ` Stefan Roese
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Roese @ 2022-11-23  8:47 UTC (permalink / raw)
  To: Mikhail Ilin, u-boot; +Cc: Stephen Warren

On 23.11.22 09:06, Mikhail Ilin wrote:
>   If memory allocation fails on line 780, then 'fail' will be
>   jumped to and 'ptr' will be null, causing it to be dereferenced it on line
>   855. Thus, before using 'ptr[i]' one must make sure that the 'ptr' pointer
>   is not NULL.

Nitpicking. You seem to have a leading space in this comment
block. Please remove next time.

> 
> Fixes: 934b14f2bb30 ("ext4: free allocations by parse_path()")
> Signed-off-by: Mikhail Ilin <ilin.mikhail.ol@gmail.com>
> ---
>   fs/ext4/ext4_common.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
> index 1185cb2c04..3cdd1a04a9 100644
> --- a/fs/ext4/ext4_common.c
> +++ b/fs/ext4/ext4_common.c
> @@ -851,10 +851,12 @@ end:
>   fail:
>   	free(depth_dirname);
>   	free(parse_dirname);
> -	for (i = 0; i < depth; i++) {
> -		if (!ptr[i])
> -			break;
> -		free(ptr[i]);
> +	if (ptr) {
> +		for (i = 0; i < depth; i++) {
> +			if (!ptr[i])
> +				break;
> +			free(ptr[i]);
> +		}
>   	}
>   	free(ptr);

Won't this fail with ptr == NULL? Please also include the free(ptr) into
the if (ptr) { } part.

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-23  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23  8:06 [PATCH] fs: ext4: Fix dereferencing the null pointer 'ptr' Mikhail Ilin
2022-11-23  8:47 ` Stefan Roese

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.