[PATCH 2/3] mpi: fix missing fields in an empty point and the mpi_clear requires a non-empty argument.

Tianjia Zhang tianjia.zhang at linux.alibaba.com
Sun Dec 22 10:15:32 CET 2019


* mpi/ec.c (_gcry_mpi_point_set): Assign value to missing fields.

The problem is triggered when using the following code by
mpi_ec_get_elliptic_curve:

  elliptic_curve_t E;
  memset (&E, 0, sizeof E);
  mpi_point_set (&E->G, G->x, G->y, G->z);

Signed-off-by: Tianjia Zhang <tianjia.zhang at linux.alibaba.com>
---
 mpi/ec.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mpi/ec.c b/mpi/ec.c
index d4c4f953..94d93354 100644
--- a/mpi/ec.c
+++ b/mpi/ec.c
@@ -224,16 +224,16 @@ _gcry_mpi_point_set (mpi_point_t point,
     point = mpi_point_new (0);
 
   if (x)
-    mpi_set (point->x, x);
-  else
+    point->x = mpi_set (point->x, x);
+  else if (point->x)
     mpi_clear (point->x);
   if (y)
-    mpi_set (point->y, y);
-  else
+    point->y = mpi_set (point->y, y);
+  else if (point->y)
     mpi_clear (point->y);
   if (z)
-    mpi_set (point->z, z);
-  else
+    point->z = mpi_set (point->z, z);
+  else if (point->z)
     mpi_clear (point->z);
 
   return point;
-- 
2.17.1




More information about the Gcrypt-devel mailing list