/*
* Convert a stack of property definitions and queries into a fixed array.
* The items are sorted for efficient query. The stack is not freed.
+ * This function also checks for duplicated names and returns an error if
+ * any exist.
*/
static OSSL_PROPERTY_LIST *
-stack_to_property_list(STACK_OF(OSSL_PROPERTY_DEFINITION) *sk)
+stack_to_property_list(OSSL_LIB_CTX *ctx,
+ STACK_OF(OSSL_PROPERTY_DEFINITION) *sk)
{
const int n = sk_OSSL_PROPERTY_DEFINITION_num(sk);
OSSL_PROPERTY_LIST *r;
+ OSSL_PROPERTY_IDX prev_name_idx = 0;
int i;
r = OPENSSL_malloc(sizeof(*r)
for (i = 0; i < n; i++) {
r->properties[i] = *sk_OSSL_PROPERTY_DEFINITION_value(sk, i);
r->has_optional |= r->properties[i].optional;
+
+ /* Check for duplicated names */
+ if (i > 0 && r->properties[i].name_idx == prev_name_idx) {
+ OPENSSL_free(r);
+ ERR_raise_data(ERR_LIB_PROP, PROP_R_PARSE_FAILED,
+ "Duplicated name `%s'",
+ ossl_property_name_str(ctx, prev_name_idx));
+ return NULL;
+ }
+ prev_name_idx = r->properties[i].name_idx;
}
r->num_properties = n;
}
"HERE-->%s", s);
goto err;
}
- res = stack_to_property_list(sk);
+ res = stack_to_property_list(ctx, sk);
err:
OPENSSL_free(prop);
"HERE-->%s", s);
goto err;
}
- res = stack_to_property_list(sk);
+ res = stack_to_property_list(ctx, sk);
err:
OPENSSL_free(prop);