lib/mpi: add the return value check of kcalloc
PATCH 1/1 lib/mpi: add the return value check of kcalloc
Add the return value check of kcalloc to avoid potential NULL ptr dereference.
Signed-off-by Zizhuang Deng <[email protected]>
--- lib/mpi/mpi-mod.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/mpi/mpi-mod.c +4 -0
@@ -41,6 +41,10 @@ mpi_barrett_t mpi_barrett_init(MPI m, int copy)mpi_normalize (m); ctx =kcalloc (1 ,sizeof (*ctx),GFP_KERNEL ); +if (!ctx) { +return NULL ; + } +if (copy) { ctx->m =mpi_copy (m); ctx->m_copied =1 ;
Signature · 1 line
2.25.1
Hi Zizhuang,
Quoted 13 lines · Zizhuang Deng
Add the return value check of kcalloc to avoid potential NULL ptr dereference.
Signed-off-by Zizhuang Deng <[email protected]>--- lib/mpi/mpi-mod.c | 4 ++++ 1 file changed, 4 insertions(+)lib/mpi/mpi-mod.c +0
-0
lib/mpi/mpi-mod.c mpi_barrett_t mpi_barrett_init(MPI m, int copy) · line 43
Quoted 3 lines
lib/mpi/mpi-mod.c +0
-0@@ -41,6 +41,10 @@ mpi_barrett_t mpi_barrett_init(MPI m, int copy)mpi_normalize (m); ctx =kcalloc (1 ,sizeof (*ctx),GFP_KERNEL );
Remove this empty line.
lib/mpi/mpi-mod.c mpi_barrett_t mpi_barrett_init(MPI m, int copy) · line 50
Quoted 7 lines
lib/mpi/mpi-mod.c +4
-0+if (!ctx) { +return NULL ; + } +if (copy) { ctx->m =mpi_copy (m); ctx->m_copied =1 ;
Thanks for pointing it out. Please send a copy to linux-crypto and Herbert Xu.
Best regards,
Tianjia
Quoted 13 lines · Zizhuang Deng
Add the return value check of kcalloc to avoid potential NULL ptr dereference.
Signed-off-by Zizhuang Deng <[email protected]>--- lib/mpi/mpi-mod.c | 4 ++++ 1 file changed, 4 insertions(+)lib/mpi/mpi-mod.c +0
-0
lib/mpi/mpi-mod.c mpi_barrett_t mpi_barrett_init(MPI m, int copy) · line 47
Quoted 7 lines
lib/mpi/mpi-mod.c +4
-0@@ -41,6 +41,10 @@ mpi_barrett_t mpi_barrett_init(MPI m, int copy)mpi_normalize (m); ctx =kcalloc (1 ,sizeof (*ctx),GFP_KERNEL ); +if (!ctx) { +return NULL ; + } +
Delete the pair of curly braces, and just keep:
if (!ctx) return NULL;
Thanks.
Quoted 3 lines
lib/mpi/mpi-mod.c +0
-0if (copy) { ctx->m =mpi_copy (m); ctx->m_copied =1 ;