summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/util/asn1.c22
-rw-r--r--lib/util/asn1.h4
-rw-r--r--lib/util/tests/asn1_tests.c6
3 files changed, 16 insertions, 16 deletions
diff --git a/lib/util/asn1.c b/lib/util/asn1.c
index ec8ef3f28f..946f71359c 100644
--- a/lib/util/asn1.c
+++ b/lib/util/asn1.c
@@ -214,7 +214,7 @@ bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length,
return asn1_pop_tag(data);
}
-bool ber_write_OID_String(DATA_BLOB *blob, const char *OID)
+bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
{
uint_t v, v2;
const char *p = (const char *)OID;
@@ -230,7 +230,7 @@ bool ber_write_OID_String(DATA_BLOB *blob, const char *OID)
p = newp + 1;
/*the ber representation can't use more space then the string one */
- *blob = data_blob(NULL, strlen(OID));
+ *blob = data_blob_talloc(mem_ctx, NULL, strlen(OID));
if (!blob->data) return false;
blob->data[0] = 40*v + v2;
@@ -264,10 +264,10 @@ bool ber_write_OID_String(DATA_BLOB *blob, const char *OID)
* 1:2.5.6:0x81
* 1:2.5.6:0x8182
*/
-bool ber_write_partial_OID_String(DATA_BLOB *blob, const char *partial_oid)
+bool ber_write_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *partial_oid)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
- char *oid = talloc_strdup(mem_ctx, partial_oid);
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+ char *oid = talloc_strdup(tmp_ctx, partial_oid);
char *p;
/* truncate partial part so ber_write_OID_String() works */
@@ -277,18 +277,18 @@ bool ber_write_partial_OID_String(DATA_BLOB *blob, const char *partial_oid)
p++;
}
- if (!ber_write_OID_String(blob, oid)) {
- talloc_free(mem_ctx);
+ if (!ber_write_OID_String(mem_ctx, blob, oid)) {
+ talloc_free(tmp_ctx);
return false;
}
/* Add partially endcoded subidentifier */
if (p) {
- DATA_BLOB tmp_blob = strhex_to_data_blob(mem_ctx, p);
- data_blob_append(NULL, blob, tmp_blob.data, tmp_blob.length);
+ DATA_BLOB tmp_blob = strhex_to_data_blob(tmp_ctx, p);
+ data_blob_append(mem_ctx, blob, tmp_blob.data, tmp_blob.length);
}
- talloc_free(mem_ctx);
+ talloc_free(tmp_ctx);
return true;
}
@@ -300,7 +300,7 @@ bool asn1_write_OID(struct asn1_data *data, const char *OID)
if (!asn1_push_tag(data, ASN1_OID)) return false;
- if (!ber_write_OID_String(&blob, OID)) {
+ if (!ber_write_OID_String(NULL, &blob, OID)) {
data->has_error = true;
return false;
}
diff --git a/lib/util/asn1.h b/lib/util/asn1.h
index 3d8e37b8ab..ded3244bed 100644
--- a/lib/util/asn1.h
+++ b/lib/util/asn1.h
@@ -61,8 +61,8 @@ bool asn1_pop_tag(struct asn1_data *data);
bool asn1_write_implicit_Integer(struct asn1_data *data, int i);
bool asn1_write_Integer(struct asn1_data *data, int i);
bool asn1_write_BitString(struct asn1_data *data, const void *p, size_t length, uint8_t padding);
-bool ber_write_OID_String(DATA_BLOB *blob, const char *OID);
-bool ber_write_partial_OID_String(DATA_BLOB *blob, const char *partial_oid);
+bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID);
+bool ber_write_partial_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *partial_oid);
bool asn1_write_OID(struct asn1_data *data, const char *OID);
bool asn1_write_OctetString(struct asn1_data *data, const void *p, size_t length);
bool asn1_write_LDAPString(struct asn1_data *data, const char *s);
diff --git a/lib/util/tests/asn1_tests.c b/lib/util/tests/asn1_tests.c
index eea34daaf7..25c82227ae 100644
--- a/lib/util/tests/asn1_tests.c
+++ b/lib/util/tests/asn1_tests.c
@@ -105,7 +105,7 @@ static bool test_ber_write_OID_String(struct torture_context *tctx)
mem_ctx = talloc_new(tctx);
for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) {
- torture_assert(tctx, ber_write_OID_String(&blob, data[i].oid),
+ torture_assert(tctx, ber_write_OID_String(mem_ctx, &blob, data[i].oid),
"ber_write_OID_String failed");
hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);
@@ -163,7 +163,7 @@ static bool test_ber_write_partial_OID_String(struct torture_context *tctx)
/* ber_write_partial_OID_String() should work with not partial OIDs also */
for (i = 0; i < ARRAY_SIZE(oid_data_ok); i++) {
- torture_assert(tctx, ber_write_partial_OID_String(&blob, data[i].oid),
+ torture_assert(tctx, ber_write_partial_OID_String(mem_ctx, &blob, data[i].oid),
"ber_write_partial_OID_String failed");
hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);
@@ -178,7 +178,7 @@ static bool test_ber_write_partial_OID_String(struct torture_context *tctx)
/* ber_write_partial_OID_String() test with partial OIDs */
data = partial_oid_data_ok;
for (i = 0; i < ARRAY_SIZE(partial_oid_data_ok); i++) {
- torture_assert(tctx, ber_write_partial_OID_String(&blob, data[i].oid),
+ torture_assert(tctx, ber_write_partial_OID_String(mem_ctx, &blob, data[i].oid),
"ber_write_partial_OID_String failed");
hex_str = hex_encode_talloc(mem_ctx, blob.data, blob.length);