diff mbox series

libfrog: fix a potential null pointer dereference

Message ID 20201008035732.GA6535@magnolia (mailing list archive)
State Accepted
Headers show
Series libfrog: fix a potential null pointer dereference | expand

Commit Message

Darrick J. Wong Oct. 8, 2020, 3:57 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Apparently, gcc 10.2 thinks that it's possible for either of the calloc
arguments to be zero here, in which case it will return NULL with a zero
errno.  I suppose it's possible to do that via integer overflow in the
macro, though I find it unlikely unless someone passes in a yuuuge value.

Nevertheless, just shut up the warning by hardcoding the error number
so I can move on to nastier bugs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libfrog/bulkstat.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eric Sandeen Oct. 8, 2020, 8:16 p.m. UTC | #1
On 10/7/20 10:57 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Apparently, gcc 10.2 thinks that it's possible for either of the calloc
> arguments to be zero here, in which case it will return NULL with a zero
> errno.  I suppose it's possible to do that via integer overflow in the
> macro, though I find it unlikely unless someone passes in a yuuuge value.
> 
> Nevertheless, just shut up the warning by hardcoding the error number
> so I can move on to nastier bugs.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  libfrog/bulkstat.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libfrog/bulkstat.c b/libfrog/bulkstat.c
> index c3e5c5f804e4..195f6ea053bd 100644
> --- a/libfrog/bulkstat.c
> +++ b/libfrog/bulkstat.c
> @@ -428,7 +428,7 @@ xfrog_bulkstat_alloc_req(
>  
>  	breq = calloc(1, XFS_BULKSTAT_REQ_SIZE(nr));
>  	if (!breq)
> -		return -errno;
> +		return -ENOMEM;

Sure, why not!

Reviewed-by: Eric Sandeen <sandeen@redhat.com>
 
>  	breq->hdr.icount = nr;
>  	breq->hdr.ino = startino;
>
Christoph Hellwig Oct. 15, 2020, 8:26 a.m. UTC | #2
Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/libfrog/bulkstat.c b/libfrog/bulkstat.c
index c3e5c5f804e4..195f6ea053bd 100644
--- a/libfrog/bulkstat.c
+++ b/libfrog/bulkstat.c
@@ -428,7 +428,7 @@  xfrog_bulkstat_alloc_req(
 
 	breq = calloc(1, XFS_BULKSTAT_REQ_SIZE(nr));
 	if (!breq)
-		return -errno;
+		return -ENOMEM;
 
 	breq->hdr.icount = nr;
 	breq->hdr.ino = startino;