diff mbox series

[2/2] xfs_io: Fix do not loop through uninitialized var

Message ID 20240530223819.135697-3-preichl@redhat.com (mailing list archive)
State Accepted, archived
Headers show
Series xfsprogs: Fix some issues found by checker | expand

Commit Message

Pavel Reichl May 30, 2024, 10:38 p.m. UTC
Red Hat's covscan checker found the following issue:

xfsprogs-6.4.0/io/parent.c:115:2: var_decl: Declaring variable "count" without initializer.
xfsprogs-6.4.0/io/parent.c:134:2: uninit_use: Using uninitialized value "count".

Currently, jdm_parentpaths() returns EOPNOTSUPP and does not initialize
the count variable. The count variable is subsequently used in a for
loop, which leads to undefined behavior. Fix this by returning from the
check_parents() function immediately after checking the return value of
the jdm_parentpaths() function.

Signed-off-by: Pavel Reichl <preichl@redhat.com>
---
 io/parent.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Darrick J. Wong May 30, 2024, 10:48 p.m. UTC | #1
On Fri, May 31, 2024 at 12:38:19AM +0200, Pavel Reichl wrote:
> Red Hat's covscan checker found the following issue:
> 
> xfsprogs-6.4.0/io/parent.c:115:2: var_decl: Declaring variable "count" without initializer.
> xfsprogs-6.4.0/io/parent.c:134:2: uninit_use: Using uninitialized value "count".
> 
> Currently, jdm_parentpaths() returns EOPNOTSUPP and does not initialize
> the count variable. The count variable is subsequently used in a for
> loop, which leads to undefined behavior. Fix this by returning from the
> check_parents() function immediately after checking the return value of
> the jdm_parentpaths() function.
> 
> Signed-off-by: Pavel Reichl <preichl@redhat.com>

I'm waiting on Carlos to take the xfsprogs 6.9 stuff so that I can
resend the new parent pointer code[1] for 6.10 which blows away the last
of the old SGI pptr code.

--D

[1] https://lore.kernel.org/linux-xfs/170405006341.1804688.11009892277015794783.stgit@frogsfrogsfrogs/

> ---
>  io/parent.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/io/parent.c b/io/parent.c
> index 8f63607f..93f40997 100644
> --- a/io/parent.c
> +++ b/io/parent.c
> @@ -112,7 +112,7 @@ check_parents(parent_t *parentbuf, size_t *parentbuf_size,
>  	     jdm_fshandle_t *fshandlep, struct xfs_bstat *statp)
>  {
>  	int error, i;
> -	__u32 count;
> +	__u32 count = 0;
>  	parent_t *entryp;
>  
>  	do {
> @@ -126,7 +126,7 @@ check_parents(parent_t *parentbuf, size_t *parentbuf_size,
>  			       (unsigned long long) statp->bs_ino,
>  				strerror(errno));
>  			err_status++;
> -			break;
> +			return;
>  		}
>  	} while (error == ERANGE);
>  
> -- 
> 2.45.1
> 
>
Carlos Maiolino May 31, 2024, 9:12 a.m. UTC | #2
On Thu, May 30, 2024 at 03:48:42PM GMT, Darrick J. Wong wrote:
> On Fri, May 31, 2024 at 12:38:19AM +0200, Pavel Reichl wrote:
> > Red Hat's covscan checker found the following issue:
> >
> > xfsprogs-6.4.0/io/parent.c:115:2: var_decl: Declaring variable "count" without initializer.
> > xfsprogs-6.4.0/io/parent.c:134:2: uninit_use: Using uninitialized value "count".
> >
> > Currently, jdm_parentpaths() returns EOPNOTSUPP and does not initialize
> > the count variable. The count variable is subsequently used in a for
> > loop, which leads to undefined behavior. Fix this by returning from the
> > check_parents() function immediately after checking the return value of
> > the jdm_parentpaths() function.
> >
> > Signed-off-by: Pavel Reichl <preichl@redhat.com>
> 
> I'm waiting on Carlos to take the xfsprogs 6.9 stuff so that I can
> resend the new parent pointer code[1] for 6.10 which blows away the last
> of the old SGI pptr code.

I'm working on it :) sorry the delay should be ready most late next week.

 
> 
> --D
> 
> [1] https://lore.kernel.org/linux-xfs/170405006341.1804688.11009892277015794783.stgit@frogsfrogsfrogs/
> 
> > ---
> >  io/parent.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/io/parent.c b/io/parent.c
> > index 8f63607f..93f40997 100644
> > --- a/io/parent.c
> > +++ b/io/parent.c
> > @@ -112,7 +112,7 @@ check_parents(parent_t *parentbuf, size_t *parentbuf_size,
> >  	     jdm_fshandle_t *fshandlep, struct xfs_bstat *statp)
> >  {
> >  	int error, i;
> > -	__u32 count;
> > +	__u32 count = 0;
> >  	parent_t *entryp;
> >
> >  	do {
> > @@ -126,7 +126,7 @@ check_parents(parent_t *parentbuf, size_t *parentbuf_size,
> >  			       (unsigned long long) statp->bs_ino,
> >  				strerror(errno));
> >  			err_status++;
> > -			break;
> > +			return;
> >  		}
> >  	} while (error == ERANGE);
> >
> > --
> > 2.45.1
> >
> >
>
diff mbox series

Patch

diff --git a/io/parent.c b/io/parent.c
index 8f63607f..93f40997 100644
--- a/io/parent.c
+++ b/io/parent.c
@@ -112,7 +112,7 @@  check_parents(parent_t *parentbuf, size_t *parentbuf_size,
 	     jdm_fshandle_t *fshandlep, struct xfs_bstat *statp)
 {
 	int error, i;
-	__u32 count;
+	__u32 count = 0;
 	parent_t *entryp;
 
 	do {
@@ -126,7 +126,7 @@  check_parents(parent_t *parentbuf, size_t *parentbuf_size,
 			       (unsigned long long) statp->bs_ino,
 				strerror(errno));
 			err_status++;
-			break;
+			return;
 		}
 	} while (error == ERANGE);