openssl: Use dynamically allocated array to determine EC curves
This avoids the use of a variable length array, which should probably be avoided in general due to potential performance, portability and security issues (not in this particular case, though). Closes strongswan/strongswan#1095
This commit is contained in:
@@ -345,22 +345,26 @@ static bool ecdh_group_supported(EC_builtin_curve *curves, size_t num_curves,
|
|||||||
static void add_ecdh_features(plugin_feature_t *features,
|
static void add_ecdh_features(plugin_feature_t *features,
|
||||||
plugin_feature_t *to_add, int count, int *pos)
|
plugin_feature_t *to_add, int count, int *pos)
|
||||||
{
|
{
|
||||||
|
EC_builtin_curve *curves;
|
||||||
size_t num_curves;
|
size_t num_curves;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
num_curves = EC_get_builtin_curves(NULL, 0);
|
num_curves = EC_get_builtin_curves(NULL, 0);
|
||||||
|
|
||||||
EC_builtin_curve curves[num_curves];
|
if (num_curves)
|
||||||
|
|
||||||
num_curves = EC_get_builtin_curves(curves, num_curves);
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
{
|
||||||
if (to_add[i].kind != FEATURE_PROVIDE ||
|
curves = calloc(num_curves, sizeof(EC_builtin_curve));
|
||||||
ecdh_group_supported(curves, num_curves, to_add[i].arg.dh_group))
|
num_curves = EC_get_builtin_curves(curves, num_curves);
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
features[(*pos)++] = to_add[i];
|
if (to_add[i].kind != FEATURE_PROVIDE ||
|
||||||
|
ecdh_group_supported(curves, num_curves, to_add[i].arg.dh_group))
|
||||||
|
{
|
||||||
|
features[(*pos)++] = to_add[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
free(curves);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* OPENSSL_NO_ECDH */
|
#endif /* OPENSSL_NO_ECDH */
|
||||||
|
|||||||
Reference in New Issue
Block a user