]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
gost_prov: Avoid access to unallocated memory
authorVitaly Chikunov <vt@altlinux.org>
Sat, 8 Jan 2022 23:34:57 +0000 (02:34 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Sun, 9 Jan 2022 10:57:41 +0000 (13:57 +0300)
This should fix Coverity warning:

  *** CID 345245:    (UNINIT)
  /gost_prov.c: 71 in provider_ctx_new()
  65             && populate_gost_engine(ctx->e)) {
  66             ctx->core_handle = core;
  67
  68             /* Ugly hack */
  69             err_handle = ctx->proverr_handle;
  70         } else {
  >>>     CID 345245:    (UNINIT)
  >>>     Using uninitialized value "ctx->e" when calling "provider_ctx_free".
  71             provider_ctx_free(ctx);
  72             ctx = NULL;
  73         }
  74         return ctx;
  75     }

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
Issue: #380

gost_prov.c

index b4de15fe1e4974197bc6dbf2c7e33b1490a513ca..3d237655d6cc2eb0fd94d6837c8508e8f0d22741 100644 (file)
@@ -58,7 +58,7 @@ static PROV_CTX *provider_ctx_new(const OSSL_CORE_HANDLE *core,
 {
     PROV_CTX *ctx;
 
-    if ((ctx = malloc(sizeof(*ctx))) != NULL
+    if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) != NULL
         && (ctx->proverr_handle = proverr_new_handle(core, in)) != NULL
         && (ctx->libctx = OSSL_LIB_CTX_new()) != NULL
         && (ctx->e = ENGINE_new()) != NULL