- if(ttmp) return ttmp;
- if(!stable) return NULL;
- idx = sk_ASN1_STRING_TABLE_find(stable, &fnd);
- if(idx < 0) return NULL;
- return sk_ASN1_STRING_TABLE_value(stable, idx);
-}
-
+ }
+
+/* Return a string table pointer which can be modified: either directly
+ * from table or a copy of an internal value added to the table.
+ */
+
+static ASN1_STRING_TABLE *stable_get(int nid)
+ {
+ ASN1_STRING_TABLE *tmp, *rv;
+ /* Always need a string table so allocate one if NULL */
+ if(!stable)
+ {
+ stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
+ if (!stable)
+ return NULL;
+ }
+ tmp = ASN1_STRING_TABLE_get(nid);
+ if (tmp && tmp->flags & STABLE_FLAGS_MALLOC)
+ return tmp;
+ rv = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
+ if (!rv)
+ return NULL;
+ if (!sk_ASN1_STRING_TABLE_push(stable, rv))
+ {
+ OPENSSL_free(rv);
+ return NULL;
+ }
+ if (tmp)
+ {
+ rv->nid = tmp->nid;
+ rv->minsize = tmp->minsize;
+ rv->maxsize = tmp->maxsize;
+ rv->mask = tmp->mask;
+ rv->flags = tmp->flags | STABLE_FLAGS_MALLOC;
+ }
+ else
+ {
+ rv->minsize = -1;
+ rv->maxsize = -1;
+ rv->mask = 0;
+ rv->flags = STABLE_FLAGS_MALLOC;
+ }
+ return rv;
+ }
+