Skip to contentSkip to conversation

libfrog: fix a potential null pointer dereference

PATCH In review Darrick J. Wong 3 participants 3 messages Oct 8, 2020 – Oct 15, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libfrog: fix a potential null pointer dereference

From: Darrick J. Wong <[email protected]>

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.

---
 libfrog/bulkstat.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libfrog/bulkstat.c +1 -1
index c3e5c5f804e4..195f6ea053bd 100644
@@ -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;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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.

---
 libfrog/bulkstat.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libfrog/bulkstat.c +0 -0
index c3e5c5f804e4..195f6ea053bd 100644

libfrog/bulkstat.c xfrog_bulkstat_alloc_req( · line 431

Quoted 5 lines
libfrog/bulkstat.c +1 -1
@@ -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!

Quoted 3 lines
libfrog/bulkstat.c +0 -0
 	breq->hdr.icount = nr;
 	breq->hdr.ino = startino;