capi_get_provname: Check return values
authorKurt Roeckx <kurt@roeckx.be>
Thu, 4 Dec 2014 17:16:42 +0000 (18:16 +0100)
committerKurt Roeckx <kurt@roeckx.be>
Thu, 4 Dec 2014 22:48:44 +0000 (23:48 +0100)
Reviewed-by: Richard Levitte <levitte@openssl.org>
engines/e_capi.c

index f7876f3..87a10dd 100644 (file)
@@ -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);