From f6fa7c53479d79073cf959d7cdc496be2b2372c6 Mon Sep 17 00:00:00 2001 From: Kurt Roeckx Date: Thu, 4 Dec 2014 18:16:42 +0100 Subject: [PATCH] capi_get_provname: Check return values Reviewed-by: Richard Levitte --- engines/e_capi.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/engines/e_capi.c b/engines/e_capi.c index f7876f3bab..87a10dd4fc 100644 --- a/engines/e_capi.c +++ b/engines/e_capi.c @@ -1148,15 +1148,16 @@ static int capi_get_provname(CAPI_CTX *ctx, LPSTR *pname, DWORD *ptype, DWORD id capi_adderror(err); return 0; } - if (sizeof(TCHAR) != sizeof(char)) - name = alloca(len); - else - name = OPENSSL_malloc(len); + name = OPENSSL_malloc(len); + if (name == NULL) + { + CAPIerr(CAPI_F_CAPI_GET_PROVNAME, ERR_R_MALLOC_FAILURE); + return 0; + } if (!CryptEnumProviders(idx, NULL, 0, ptype, name, &len)) { err = GetLastError(); - if (sizeof(TCHAR) == sizeof(char)) - OPENSSL_free(name); + OPENSSL_free(name); if (err == ERROR_NO_MORE_ITEMS) return 2; CAPIerr(CAPI_F_CAPI_GET_PROVNAME, CAPI_R_CRYPTENUMPROVIDERS_ERROR); @@ -1164,7 +1165,12 @@ static int capi_get_provname(CAPI_CTX *ctx, LPSTR *pname, DWORD *ptype, DWORD id return 0; } if (sizeof(TCHAR) != sizeof(char)) + { *pname = wide_to_asc((WCHAR *)name); + OPENSSL_free(name); + if (*pname == NULL) + return 0; + } else *pname = (char *)name; CAPI_trace(ctx, "capi_get_provname, returned name=%s, type=%d\n", *pname, *ptype); -- 2.40.0