[patch] mpi/mpi-mpow: NULL dereference on allocation failure

Subsystems: library code, the rest

STALE5441d

3 messages, 3 authors, 2011-11-21 · open the first message on its own page

[patch] mpi/mpi-mpow: NULL dereference on allocation failure

From: Dan Carpenter <hidden>
Date: 2011-11-21 14:51:13

We can't call mpi_free() on the elements if the first kzalloc() fails.

Signed-off-by: Dan Carpenter <redacted>
diff --git a/lib/mpi/mpi-mpow.c b/lib/mpi/mpi-mpow.c
index 4cc7593..7328d0d 100644
--- a/lib/mpi/mpi-mpow.c
+++ b/lib/mpi/mpi-mpow.c
@@ -73,7 +73,7 @@ int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI m)
 
 	G = kzalloc((1 << k) * sizeof *G, GFP_KERNEL);
 	if (!G)
-		goto nomem;
+		goto err_out;
 
 	/* and calculate */
 	tmp = mpi_alloc(mpi_get_nlimbs(m) + 1);
@@ -129,5 +129,6 @@ nomem:
 	for (i = 0; i < (1 << k); i++)
 		mpi_free(G[i]);
 	kfree(G);
+err_out:
 	return rc;
 }

Re: [patch] mpi/mpi-mpow: NULL dereference on allocation failure

From: Kasatkin, Dmitry <hidden>
Date: 2011-11-21 15:19:14

On Mon, Nov 21, 2011 at 4:50 PM, Dan Carpenter [off-list ref] wrote:
We can't call mpi_free() on the elements if the first kzalloc() fails.

Signed-off-by: Dan Carpenter <redacted>
Signed-off-by: Dmitry Kasatkin <redacted>
quoted hunk
diff --git a/lib/mpi/mpi-mpow.c b/lib/mpi/mpi-mpow.c
index 4cc7593..7328d0d 100644
--- a/lib/mpi/mpi-mpow.c
+++ b/lib/mpi/mpi-mpow.c
@@ -73,7 +73,7 @@ int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI m)
       G = kzalloc((1 << k) * sizeof *G, GFP_KERNEL);
       if (!G)
-               goto nomem;
+               goto err_out;

       /* and calculate */
       tmp = mpi_alloc(mpi_get_nlimbs(m) + 1);
@@ -129,5 +129,6 @@ nomem:
       for (i = 0; i < (1 << k); i++)
               mpi_free(G[i]);
       kfree(G);
+err_out:
       return rc;
 }

Re: [patch] mpi/mpi-mpow: NULL dereference on allocation failure

From: walter harms <hidden>
Date: 2011-11-21 17:00:38


Am 21.11.2011 15:50, schrieb Dan Carpenter:
quoted hunk
We can't call mpi_free() on the elements if the first kzalloc() fails.

Signed-off-by: Dan Carpenter <redacted>
diff --git a/lib/mpi/mpi-mpow.c b/lib/mpi/mpi-mpow.c
index 4cc7593..7328d0d 100644
--- a/lib/mpi/mpi-mpow.c
+++ b/lib/mpi/mpi-mpow.c
@@ -73,7 +73,7 @@ int mpi_mulpowm(MPI res, MPI *basearray, MPI *exparray, MPI m)
 
 	G = kzalloc((1 << k) * sizeof *G, GFP_KERNEL);
 	if (!G)
-		goto nomem;
+		goto err_out;
 
 	/* and calculate */
 	tmp = mpi_alloc(mpi_get_nlimbs(m) + 1);
@@ -129,5 +129,6 @@ nomem:
 	for (i = 0; i < (1 << k); i++)
 		mpi_free(G[i]);
 	kfree(G);
+err_out:
 	return rc;
 }
the patch is ok
but is there any reason *not* to use a more nice name that 'G'
something more descriptive perhaps ?

re,
 wh

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help