Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/bytestring/cbb.c

raw
1 // Copyright (c) 2014, Google Inc.
2 // SPDX-License-Identifier: ISC
3
4 #include <openssl/bytestring.h>
5
6 #include <assert.h>
7 #include <limits.h>
8 #include <string.h>
9
10 #include <openssl/mem.h>
11 #include <openssl/err.h>
12
13 #include "../internal.h"
14
15
16 void CBB_zero(CBB *cbb) {
17 OPENSSL_memset(cbb, 0, sizeof(CBB));
18 }
19
20 static void cbb_init(CBB *cbb, uint8_t *buf, size_t cap, int can_resize) {
21 cbb->is_child = 0;
22 cbb->child = NULL;
23 cbb->u.base.buf = buf;
24 cbb->u.base.len = 0;
25 cbb->u.base.cap = cap;
26 cbb->u.base.can_resize = can_resize;
27 cbb->u.base.error = 0;
28 }
29
30 int CBB_init(CBB *cbb, size_t initial_capacity) {
31 CBB_zero(cbb);
32
33 uint8_t *buf = OPENSSL_malloc(initial_capacity);
34 if (initial_capacity > 0 && buf == NULL) {
35 return 0;
36 }
37
38 cbb_init(cbb, buf, initial_capacity, /*can_resize=*/1);
39 return 1;
40 }
41
42 int CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len) {
43 CBB_zero(cbb);
44 cbb_init(cbb, buf, len, /*can_resize=*/0);
45 return 1;
46 }
47
48 void CBB_cleanup(CBB *cbb) {
49 // Child |CBB|s are non-owning. They are implicitly discarded and should not
50 // be used with |CBB_cleanup| or |ScopedCBB|.
51 assert(!cbb->is_child);
52 if (cbb->is_child) {
53 return;
54 }
55
56 if (cbb->u.base.can_resize) {
57 OPENSSL_free(cbb->u.base.buf);
58 }
59 }
60
61 static int cbb_buffer_reserve(struct cbb_buffer_st *base, uint8_t **out,
62 size_t len) {
63 if (base == NULL) {
64 return 0;
65 }
66
67 size_t newlen = base->len + len;
68 if (newlen < base->len) {
69 // Overflow
70 OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
71 goto err;
72 }
73
74 if (newlen > base->cap) {
75 if (!base->can_resize) {
76 OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
77 goto err;
78 }
79
80 size_t newcap = base->cap * 2;
81 if (newcap < base->cap || newcap < newlen) {
82 newcap = newlen;
83 }
84 uint8_t *newbuf = OPENSSL_realloc(base->buf, newcap);
85 if (newbuf == NULL) {
86 goto err;
87 }
88
89 base->buf = newbuf;
90 base->cap = newcap;
91 }
92
93 if (out) {
94 *out = base->buf + base->len;
95 }
96
97 return 1;
98
99 err:
100 base->error = 1;
101 return 0;
102 }
103
104 static int cbb_buffer_add(struct cbb_buffer_st *base, uint8_t **out,
105 size_t len) {
106 if (!cbb_buffer_reserve(base, out, len)) {
107 return 0;
108 }
109 // This will not overflow or |cbb_buffer_reserve| would have failed.
110 base->len += len;
111 return 1;
112 }
113
114 int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len) {
115 if (cbb->is_child) {
116 OPENSSL_PUT_ERROR(CRYPTO, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
117 return 0;
118 }
119
120 if (!CBB_flush(cbb)) {
121 return 0;
122 }
123
124 if (cbb->u.base.can_resize && (out_data == NULL || out_len == NULL)) {
125 // |out_data| and |out_len| can only be NULL if the CBB is fixed.
126 return 0;
127 }
128
129 if (out_data != NULL) {
130 *out_data = cbb->u.base.buf;
131 }
132 if (out_len != NULL) {
133 *out_len = cbb->u.base.len;
134 }
135 cbb->u.base.buf = NULL;
136 CBB_cleanup(cbb);
137 return 1;
138 }
139
140 static struct cbb_buffer_st *cbb_get_base(CBB *cbb) {
141 if (cbb->is_child) {
142 return cbb->u.child.base;
143 }
144 return &cbb->u.base;
145 }
146
147 static void cbb_on_error(CBB *cbb) {
148 // Due to C's lack of destructors and |CBB|'s auto-flushing API, a failing
149 // |CBB|-taking function may leave a dangling pointer to a child |CBB|. As a
150 // result, the convention is callers may not write to |CBB|s that have failed.
151 // But, as a safety measure, we lock the |CBB| into an error state. Once the
152 // error bit is set, |cbb->child| will not be read.
153 //
154 // TODO(davidben): This still isn't quite ideal. A |CBB| function *outside*
155 // this file may originate an error while the |CBB| points to a local child.
156 // In that case we don't set the error bit and are reliant on the error
157 // convention. Perhaps we allow |CBB_cleanup| on child |CBB|s and make every
158 // child's |CBB_cleanup| set the error bit if unflushed. That will be
159 // convenient for C++ callers, but very tedious for C callers. So C callers
160 // perhaps should get a |CBB_on_error| function that can be, less tediously,
161 // stuck in a |goto err| block.
162 cbb_get_base(cbb)->error = 1;
163
164 // Clearing the pointer is not strictly necessary, but GCC's dangling pointer
165 // warning does not know |cbb->child| will not be read once |error| is set
166 // above.
167 cbb->child = NULL;
168 }
169
170 // CBB_flush recurses and then writes out any pending length prefix. The
171 // current length of the underlying base is taken to be the length of the
172 // length-prefixed data.
173 int CBB_flush(CBB *cbb) {
174 // If |base| has hit an error, the buffer is in an undefined state, so
175 // fail all following calls. In particular, |cbb->child| may point to invalid
176 // memory.
177 struct cbb_buffer_st *base = cbb_get_base(cbb);
178 if (base == NULL || base->error) {
179 return 0;
180 }
181
182 if (cbb->child == NULL) {
183 // Nothing to flush.
184 return 1;
185 }
186
187 assert(cbb->child->is_child);
188 struct cbb_child_st *child = &cbb->child->u.child;
189 assert(child->base == base);
190 size_t child_start = child->offset + child->pending_len_len;
191
192 if (!CBB_flush(cbb->child) ||
193 child_start < child->offset ||
194 base->len < child_start) {
195 goto err;
196 }
197
198 size_t len = base->len - child_start;
199
200 if (child->pending_is_asn1) {
201 // For ASN.1 we assume that we'll only need a single byte for the length.
202 // If that turned out to be incorrect, we have to move the contents along
203 // in order to make space.
204 uint8_t len_len;
205 uint8_t initial_length_byte;
206
207 assert (child->pending_len_len == 1);
208
209 if (len > 0xfffffffe) {
210 OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
211 // Too large.
212 goto err;
213 } else if (len > 0xffffff) {
214 len_len = 5;
215 initial_length_byte = 0x80 | 4;
216 } else if (len > 0xffff) {
217 len_len = 4;
218 initial_length_byte = 0x80 | 3;
219 } else if (len > 0xff) {
220 len_len = 3;
221 initial_length_byte = 0x80 | 2;
222 } else if (len > 0x7f) {
223 len_len = 2;
224 initial_length_byte = 0x80 | 1;
225 } else {
226 len_len = 1;
227 initial_length_byte = (uint8_t)len;
228 len = 0;
229 }
230
231 if (len_len != 1) {
232 // We need to move the contents along in order to make space.
233 size_t extra_bytes = len_len - 1;
234 if (!cbb_buffer_add(base, NULL, extra_bytes)) {
235 goto err;
236 }
237 OPENSSL_memmove(base->buf + child_start + extra_bytes,
238 base->buf + child_start, len);
239 }
240 base->buf[child->offset++] = initial_length_byte;
241 child->pending_len_len = len_len - 1;
242 }
243
244 for (size_t i = child->pending_len_len - 1; i < child->pending_len_len; i--) {
245 base->buf[child->offset + i] = (uint8_t)len;
246 len >>= 8;
247 }
248 if (len != 0) {
249 OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
250 goto err;
251 }
252
253 child->base = NULL;
254 cbb->child = NULL;
255
256 return 1;
257
258 err:
259 cbb_on_error(cbb);
260 return 0;
261 }
262
263 const uint8_t *CBB_data(const CBB *cbb) {
264 assert(cbb->child == NULL);
265 if (cbb->is_child) {
266 return cbb->u.child.base->buf + cbb->u.child.offset +
267 cbb->u.child.pending_len_len;
268 }
269 return cbb->u.base.buf;
270 }
271
272 size_t CBB_len(const CBB *cbb) {
273 assert(cbb->child == NULL);
274 if (cbb->is_child) {
275 assert(cbb->u.child.offset + cbb->u.child.pending_len_len <=
276 cbb->u.child.base->len);
277 return cbb->u.child.base->len - cbb->u.child.offset -
278 cbb->u.child.pending_len_len;
279 }
280 return cbb->u.base.len;
281 }
282
283 static int cbb_add_child(CBB *cbb, CBB *out_child, uint8_t len_len,
284 int is_asn1) {
285 assert(cbb->child == NULL);
286 assert(!is_asn1 || len_len == 1);
287 struct cbb_buffer_st *base = cbb_get_base(cbb);
288 size_t offset = base->len;
289
290 // Reserve space for the length prefix.
291 uint8_t *prefix_bytes;
292 if (!cbb_buffer_add(base, &prefix_bytes, len_len)) {
293 return 0;
294 }
295 OPENSSL_memset(prefix_bytes, 0, len_len);
296
297 CBB_zero(out_child);
298 out_child->is_child = 1;
299 out_child->u.child.base = base;
300 out_child->u.child.offset = offset;
301 out_child->u.child.pending_len_len = len_len;
302 out_child->u.child.pending_is_asn1 = is_asn1;
303 cbb->child = out_child;
304 return 1;
305 }
306
307 static int cbb_add_length_prefixed(CBB *cbb, CBB *out_contents,
308 uint8_t len_len) {
309 if (!CBB_flush(cbb)) {
310 return 0;
311 }
312
313 return cbb_add_child(cbb, out_contents, len_len, /*is_asn1=*/0);
314 }
315
316 int CBB_add_u8_length_prefixed(CBB *cbb, CBB *out_contents) {
317 return cbb_add_length_prefixed(cbb, out_contents, 1);
318 }
319
320 int CBB_add_u16_length_prefixed(CBB *cbb, CBB *out_contents) {
321 return cbb_add_length_prefixed(cbb, out_contents, 2);
322 }
323
324 int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents) {
325 return cbb_add_length_prefixed(cbb, out_contents, 3);
326 }
327
328 // add_base128_integer encodes |v| as a big-endian base-128 integer where the
329 // high bit of each byte indicates where there is more data. This is the
330 // encoding used in DER for both high tag number form and OID components.
331 static int add_base128_integer(CBB *cbb, uint64_t v) {
332 unsigned len_len = 0;
333 uint64_t copy = v;
334 while (copy > 0) {
335 len_len++;
336 copy >>= 7;
337 }
338 if (len_len == 0) {
339 len_len = 1; // Zero is encoded with one byte.
340 }
341 for (unsigned i = len_len - 1; i < len_len; i--) {
342 uint8_t byte = (v >> (7 * i)) & 0x7f;
343 if (i != 0) {
344 // The high bit denotes whether there is more data.
345 byte |= 0x80;
346 }
347 if (!CBB_add_u8(cbb, byte)) {
348 return 0;
349 }
350 }
351 return 1;
352 }
353
354 int CBB_add_asn1(CBB *cbb, CBB *out_contents, CBS_ASN1_TAG tag) {
355 if (!CBB_flush(cbb)) {
356 return 0;
357 }
358
359 // Split the tag into leading bits and tag number.
360 uint8_t tag_bits = (tag >> CBS_ASN1_TAG_SHIFT) & 0xe0;
361 CBS_ASN1_TAG tag_number = tag & CBS_ASN1_TAG_NUMBER_MASK;
362 if (tag_number >= 0x1f) {
363 // Set all the bits in the tag number to signal high tag number form.
364 if (!CBB_add_u8(cbb, tag_bits | 0x1f) ||
365 !add_base128_integer(cbb, tag_number)) {
366 return 0;
367 }
368 } else if (!CBB_add_u8(cbb, tag_bits | tag_number)) {
369 return 0;
370 }
371
372 // Reserve one byte of length prefix. |CBB_flush| will finish it later.
373 return cbb_add_child(cbb, out_contents, /*len_len=*/1, /*is_asn1=*/1);
374 }
375
376 int CBB_add_bytes(CBB *cbb, const uint8_t *data, size_t len) {
377 uint8_t *out;
378 if (!CBB_add_space(cbb, &out, len)) {
379 return 0;
380 }
381 OPENSSL_memcpy(out, data, len);
382 return 1;
383 }
384
385 int CBB_add_zeros(CBB *cbb, size_t len) {
386 uint8_t *out;
387 if (!CBB_add_space(cbb, &out, len)) {
388 return 0;
389 }
390 OPENSSL_memset(out, 0, len);
391 return 1;
392 }
393
394 int CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len) {
395 if (!CBB_flush(cbb) ||
396 !cbb_buffer_add(cbb_get_base(cbb), out_data, len)) {
397 return 0;
398 }
399 return 1;
400 }
401
402 int CBB_reserve(CBB *cbb, uint8_t **out_data, size_t len) {
403 if (!CBB_flush(cbb) ||
404 !cbb_buffer_reserve(cbb_get_base(cbb), out_data, len)) {
405 return 0;
406 }
407 return 1;
408 }
409
410 int CBB_did_write(CBB *cbb, size_t len) {
411 struct cbb_buffer_st *base = cbb_get_base(cbb);
412 size_t newlen = base->len + len;
413 if (cbb->child != NULL ||
414 newlen < base->len ||
415 newlen > base->cap) {
416 return 0;
417 }
418 base->len = newlen;
419 return 1;
420 }
421
422 static int cbb_add_u(CBB *cbb, uint64_t v, size_t len_len) {
423 uint8_t *buf;
424 if (!CBB_add_space(cbb, &buf, len_len)) {
425 return 0;
426 }
427
428 for (size_t i = len_len - 1; i < len_len; i--) {
429 buf[i] = v;
430 v >>= 8;
431 }
432
433 // |v| must fit in |len_len| bytes.
434 if (v != 0) {
435 cbb_on_error(cbb);
436 return 0;
437 }
438
439 return 1;
440 }
441
442 int CBB_add_u8(CBB *cbb, uint8_t value) {
443 return cbb_add_u(cbb, value, 1);
444 }
445
446 int CBB_add_u16(CBB *cbb, uint16_t value) {
447 return cbb_add_u(cbb, value, 2);
448 }
449
450 int CBB_add_u16le(CBB *cbb, uint16_t value) {
451 return CBB_add_u16(cbb, CRYPTO_bswap2(value));
452 }
453
454 int CBB_add_u24(CBB *cbb, uint32_t value) {
455 return cbb_add_u(cbb, value, 3);
456 }
457
458 int CBB_add_u32(CBB *cbb, uint32_t value) {
459 return cbb_add_u(cbb, value, 4);
460 }
461
462 int CBB_add_u32le(CBB *cbb, uint32_t value) {
463 return CBB_add_u32(cbb, CRYPTO_bswap4(value));
464 }
465
466 int CBB_add_u64(CBB *cbb, uint64_t value) {
467 return cbb_add_u(cbb, value, 8);
468 }
469
470 int CBB_add_u64le(CBB *cbb, uint64_t value) {
471 return CBB_add_u64(cbb, CRYPTO_bswap8(value));
472 }
473
474 void CBB_discard_child(CBB *cbb) {
475 if (cbb->child == NULL) {
476 return;
477 }
478
479 struct cbb_buffer_st *base = cbb_get_base(cbb);
480 assert(cbb->child->is_child);
481 base->len = cbb->child->u.child.offset;
482
483 cbb->child->u.child.base = NULL;
484 cbb->child = NULL;
485 }
486
487 int CBB_add_asn1_uint64(CBB *cbb, uint64_t value) {
488 return CBB_add_asn1_uint64_with_tag(cbb, value, CBS_ASN1_INTEGER);
489 }
490
491 int CBB_add_asn1_uint64_with_tag(CBB *cbb, uint64_t value, CBS_ASN1_TAG tag) {
492 CBB child;
493 if (!CBB_add_asn1(cbb, &child, tag)) {
494 goto err;
495 }
496
497 int started = 0;
498 for (size_t i = 0; i < 8; i++) {
499 uint8_t byte = (value >> 8 * (7 - i)) & 0xff;
500 if (!started) {
501 if (byte == 0) {
502 // Don't encode leading zeros.
503 continue;
504 }
505 // If the high bit is set, add a padding byte to make it
506 // unsigned.
507 if ((byte & 0x80) && !CBB_add_u8(&child, 0)) {
508 goto err;
509 }
510 started = 1;
511 }
512 if (!CBB_add_u8(&child, byte)) {
513 goto err;
514 }
515 }
516
517 // 0 is encoded as a single 0, not the empty string.
518 if (!started && !CBB_add_u8(&child, 0)) {
519 goto err;
520 }
521
522 return CBB_flush(cbb);
523
524 err:
525 cbb_on_error(cbb);
526 return 0;
527 }
528
529 int CBB_add_asn1_int64(CBB *cbb, int64_t value) {
530 return CBB_add_asn1_int64_with_tag(cbb, value, CBS_ASN1_INTEGER);
531 }
532
533 int CBB_add_asn1_int64_with_tag(CBB *cbb, int64_t value, CBS_ASN1_TAG tag) {
534 if (value >= 0) {
535 return CBB_add_asn1_uint64_with_tag(cbb, (uint64_t)value, tag);
536 }
537
538 uint8_t bytes[sizeof(int64_t)];
539 memcpy(bytes, &value, sizeof(value));
540 // Skip leading sign-extension bytes unless they are necessary.
541 #ifdef OPENSSL_BIG_ENDIAN
542 int start = 0;
543 while (start < 7 && (bytes[start] == 0xff && (bytes[start + 1] & 0x80))) {
544 start++;
545 }
546 #else
547 int start = 7;
548 while (start > 0 && (bytes[start] == 0xff && (bytes[start - 1] & 0x80))) {
549 start--;
550 }
551 #endif
552 CBB child;
553 if (!CBB_add_asn1(cbb, &child, tag)) {
554 goto err;
555 }
556 #ifdef OPENSSL_BIG_ENDIAN
557 for (int i = start; i <= 7; i++) {
558 #else
559 for (int i = start; i >= 0; i--) {
560 #endif
561 if (!CBB_add_u8(&child, bytes[i])) {
562 goto err;
563 }
564 }
565 return CBB_flush(cbb);
566
567 err:
568 cbb_on_error(cbb);
569 return 0;
570 }
571
572 int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
573 CBB child;
574 if (!CBB_add_asn1(cbb, &child, CBS_ASN1_OCTETSTRING) ||
575 !CBB_add_bytes(&child, data, data_len) ||
576 !CBB_flush(cbb)) {
577 cbb_on_error(cbb);
578 return 0;
579 }
580
581 return 1;
582 }
583
584 int CBB_add_asn1_bool(CBB *cbb, int value) {
585 CBB child;
586 if (!CBB_add_asn1(cbb, &child, CBS_ASN1_BOOLEAN) ||
587 !CBB_add_u8(&child, value != 0 ? 0xff : 0) ||
588 !CBB_flush(cbb)) {
589 cbb_on_error(cbb);
590 return 0;
591 }
592
593 return 1;
594 }
595
596 // parse_dotted_decimal parses one decimal component from |cbs|, where |cbs| is
597 // an OID literal, e.g., "1.2.840.113554.4.1.72585". It consumes both the
598 // component and the dot, so |cbs| may be passed into the function again for the
599 // next value.
600 static int parse_dotted_decimal(CBS *cbs, uint64_t *out) {
601 if (!CBS_get_u64_decimal(cbs, out)) {
602 return 0;
603 }
604
605 // The integer must have either ended at the end of the string, or a
606 // non-terminal dot, which should be consumed. If the string ends with a dot,
607 // this is not a valid OID string.
608 uint8_t dot;
609 return !CBS_get_u8(cbs, &dot) || (dot == '.' && CBS_len(cbs) > 0);
610 }
611
612 int CBB_add_asn1_oid_from_text(CBB *cbb, const char *text, size_t len) {
613 if (!CBB_flush(cbb)) {
614 return 0;
615 }
616
617 CBS cbs;
618 CBS_init(&cbs, (const uint8_t *)text, len);
619
620 // OIDs must have at least two components.
621 uint64_t a, b;
622 if (!parse_dotted_decimal(&cbs, &a) ||
623 !parse_dotted_decimal(&cbs, &b)) {
624 return 0;
625 }
626
627 // The first component is encoded as 40 * |a| + |b|. This assumes that |a| is
628 // 0, 1, or 2 and that, when it is 0 or 1, |b| is at most 39.
629 if (a > 2 ||
630 (a < 2 && b > 39) ||
631 b > UINT64_MAX - 80 ||
632 !add_base128_integer(cbb, 40u * a + b)) {
633 return 0;
634 }
635
636 // The remaining components are encoded unmodified.
637 while (CBS_len(&cbs) > 0) {
638 if (!parse_dotted_decimal(&cbs, &a) ||
639 !add_base128_integer(cbb, a)) {
640 return 0;
641 }
642 }
643
644 return 1;
645 }
646
647 static int compare_set_of_element(const void *a_ptr, const void *b_ptr) {
648 // See X.690, section 11.6 for the ordering. They are sorted in ascending
649 // order by their DER encoding.
650 const CBS *a = a_ptr, *b = b_ptr;
651 size_t a_len = CBS_len(a), b_len = CBS_len(b);
652 size_t min_len = a_len < b_len ? a_len : b_len;
653 int ret = OPENSSL_memcmp(CBS_data(a), CBS_data(b), min_len);
654 if (ret != 0) {
655 return ret;
656 }
657 if (a_len == b_len) {
658 return 0;
659 }
660 // If one is a prefix of the other, the shorter one sorts first. (This is not
661 // actually reachable. No DER encoding is a prefix of another DER encoding.)
662 return a_len < b_len ? -1 : 1;
663 }
664
665 int CBB_flush_asn1_set_of(CBB *cbb) {
666 if (!CBB_flush(cbb)) {
667 return 0;
668 }
669
670 CBS cbs;
671 size_t num_children = 0;
672 CBS_init(&cbs, CBB_data(cbb), CBB_len(cbb));
673 while (CBS_len(&cbs) != 0) {
674 if (!CBS_get_any_asn1_element(&cbs, NULL, NULL, NULL)) {
675 OPENSSL_PUT_ERROR(CRYPTO, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
676 return 0;
677 }
678 num_children++;
679 }
680
681 if (num_children < 2) {
682 return 1; // Nothing to do. This is the common case for X.509.
683 }
684
685 // Parse out the children and sort. We alias them into a copy of so they
686 // remain valid as we rewrite |cbb|.
687 int ret = 0;
688 size_t buf_len = CBB_len(cbb);
689 uint8_t *buf = OPENSSL_memdup(CBB_data(cbb), buf_len);
690 CBS *children = OPENSSL_calloc(num_children, sizeof(CBS));
691 if (buf == NULL || children == NULL) {
692 goto err;
693 }
694 CBS_init(&cbs, buf, buf_len);
695 for (size_t i = 0; i < num_children; i++) {
696 if (!CBS_get_any_asn1_element(&cbs, &children[i], NULL, NULL)) {
697 goto err;
698 }
699 }
700 qsort(children, num_children, sizeof(CBS), compare_set_of_element);
701
702 // Write the contents back in the new order.
703 uint8_t *out = (uint8_t *)CBB_data(cbb);
704 size_t offset = 0;
705 for (size_t i = 0; i < num_children; i++) {
706 OPENSSL_memcpy(out + offset, CBS_data(&children[i]), CBS_len(&children[i]));
707 offset += CBS_len(&children[i]);
708 }
709 assert(offset == buf_len);
710
711 ret = 1;
712
713 err:
714 OPENSSL_free(buf);
715 OPENSSL_free(children);
716 return ret;
717 }