Skip to contentSkip to conversation

lib/mpi: Fixed erroneous check on return value of mpi_resize()

PATCH In review Adarsh J 4 participants 4 messages May 5, 2012 – May 7, 2012

lore
Share & tools
lore

Adarsh J

author
#0 lore raw

PATCH 1/1 lib/mpi: Fixed erroneous check on return value of mpi_resize()

mpi_resize() returns -ENOMEM on error and 0 on success.

---
 lib/mpi/mpicoder.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/mpi/mpicoder.c +1 -1
index f26b41f..9949b69 100644
@@ -98,7 +98,7 @@ int mpi_fromstr(MPI val, const char *str)
 	nbytes = (nbits + 7) / 8;
 	nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB;
 	if (val->alloced < nlimbs)
-		if (!mpi_resize(val, nlimbs))
+		if (mpi_resize(val, nlimbs) < 0)
 			return -ENOMEM;
 	i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
 	i %= BYTES_PER_MPI_LIMB;
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 1 line · Adarsh J

mpi_resize() returns -ENOMEM on error and 0 on success.

Good catch.

But it seems to me that mpi_fromstr() has no in-tree users. Also, mpi_fromstr() in RHEL 5.8/6.2 has no users. We forgot to exclude when adding MPI support?

Quoted 21 lines
---
 lib/mpi/mpicoder.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/mpi/mpicoder.c +1 -1
index f26b41f..9949b69 100644
@@ -98,7 +98,7 @@ int mpi_fromstr(MPI val, const char *str)
 	nbytes = (nbits + 7) / 8;
 	nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB;
 	if (val->alloced < nlimbs)
-		if (!mpi_resize(val, nlimbs))
+		if (mpi_resize(val, nlimbs) < 0)
 			return -ENOMEM;
 	i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
 	i %= BYTES_PER_MPI_LIMB;
Signature · 1 line
1.7.9.5
#2 lore raw
Quoted 8 lines · Tetsuo Handa
Quoted 1 line · Adarsh J

mpi_resize() returns -ENOMEM on error and 0 on success.

Good catch.

But it seems to me that mpi_fromstr() has no in-tree users. Also, mpi_fromstr() in RHEL 5.8/6.2 has no users. We forgot to exclude when adding MPI support?

If that's the case, then it should be removed.

(Removed root@ from cc:)

Quoted 23 lines
Quoted 22 lines
---
 lib/mpi/mpicoder.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/mpi/mpicoder.c +1 -1
index f26b41f..9949b69 100644
@@ -98,7 +98,7 @@ int mpi_fromstr(MPI val, const char *str)
 	nbytes = (nbits + 7) / 8;
 	nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB;
 	if (val->alloced < nlimbs)
-		if (!mpi_resize(val, nlimbs))
+		if (mpi_resize(val, nlimbs) < 0)
 			return -ENOMEM;
 	i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
 	i %= BYTES_PER_MPI_LIMB;
Signature · 1 line
1.7.9.5
Signature · 2 lines
James Morris
<[email protected]>
Acked-by on v1 1/1
#3 lore raw
In reply to Adarsh J
Quoted 3 lines · Adarsh J

mpi_resize() returns -ENOMEM on error and 0 on success.

Thanks.

Quoted 24 lines

---
 lib/mpi/mpicoder.c |    2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
lib/mpi/mpicoder.c +1 -2
index f26b41f..9949b69 100644
@@ -98,7 +98,7 @@ int mpi_fromstr(MPI val, const char *str)
        nbytes = (nbits + 7) / 8;
        nlimbs = (nbytes + BYTES_PER_MPI_LIMB - 1) / BYTES_PER_MPI_LIMB;
        if (val->alloced < nlimbs)
-               if (!mpi_resize(val, nlimbs))
+               if (mpi_resize(val, nlimbs) < 0)
                        return -ENOMEM;
        i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB;
        i %= BYTES_PER_MPI_LIMB;
--

1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html