diff options
| author | beck <> | 2016-03-17 03:51:49 +0000 |
|---|---|---|
| committer | beck <> | 2016-03-17 03:51:49 +0000 |
| commit | a40c5f7320dab09c9216fa636bbf22949be11912 (patch) | |
| tree | fb3f284d19c426c841577ed12ace57d4cf8cf5e7 /src/lib/libc | |
| parent | 22eed2e943ba62fc8032bff2092946419e60bd52 (diff) | |
| download | openbsd-a40c5f7320dab09c9216fa636bbf22949be11912.tar.gz openbsd-a40c5f7320dab09c9216fa636bbf22949be11912.tar.bz2 openbsd-a40c5f7320dab09c9216fa636bbf22949be11912.zip | |
explicit_bzero for asn1 objects on free. Too often these contain sensitive information
and they should not be a performance bottleneck
ok miod@ krw@
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_object.c | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index fcd6aa91fe..5bf450d0e1 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: a_object.c,v 1.25 2016/03/06 18:05:00 beck Exp $ */ | 1 | /* $OpenBSD: a_object.c,v 1.26 2016/03/17 03:51:49 beck Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -225,23 +225,29 @@ i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | |||
| 225 | int | 225 | int |
| 226 | i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | 226 | i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) |
| 227 | { | 227 | { |
| 228 | char buf[80], *p = buf; | 228 | char *tmp = NULL; |
| 229 | int i; | 229 | size_t tlen = 256; |
| 230 | int i = -1; | ||
| 230 | 231 | ||
| 231 | if ((a == NULL) || (a->data == NULL)) | 232 | if ((a == NULL) || (a->data == NULL)) |
| 232 | return(BIO_write(bp, "NULL",4)); | 233 | return(BIO_write(bp, "NULL", 4)); |
| 233 | i = i2t_ASN1_OBJECT(buf, sizeof buf, a); | 234 | if ((tmp = malloc(tlen)) == NULL) |
| 234 | if (i > (int)(sizeof(buf) - 1)) { | 235 | return -1; |
| 235 | p = malloc(i + 1); | 236 | i = i2t_ASN1_OBJECT(tmp, tlen, a); |
| 236 | if (!p) | 237 | if (i > (int)(tlen - 1)) { |
| 238 | explicit_bzero(tmp, tlen); | ||
| 239 | free(tmp); | ||
| 240 | if ((tmp = malloc(i + 1)) == NULL) | ||
| 237 | return -1; | 241 | return -1; |
| 238 | i2t_ASN1_OBJECT(p, i + 1, a); | 242 | tlen = i + 1; |
| 243 | i = i2t_ASN1_OBJECT(tmp, tlen, a); | ||
| 239 | } | 244 | } |
| 240 | if (i <= 0) | 245 | if (i <= 0) |
| 241 | return BIO_write(bp, "<INVALID>", 9); | 246 | i = BIO_write(bp, "<INVALID>", 9); |
| 242 | BIO_write(bp, p, i); | 247 | else |
| 243 | if (p != buf) | 248 | i = BIO_write(bp, tmp, i); |
| 244 | free(p); | 249 | explicit_bzero(tmp, tlen); |
| 250 | free(tmp); | ||
| 245 | return (i); | 251 | return (i); |
| 246 | } | 252 | } |
| 247 | 253 | ||
| @@ -317,18 +323,15 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len) | |||
| 317 | p = *pp; | 323 | p = *pp; |
| 318 | /* detach data from object */ | 324 | /* detach data from object */ |
| 319 | data = (unsigned char *)ret->data; | 325 | data = (unsigned char *)ret->data; |
| 320 | ret->data = NULL; | 326 | if (data != NULL) |
| 321 | /* once detached we can change it */ | 327 | explicit_bzero(data, ret->length); |
| 322 | if ((data == NULL) || (ret->length < length)) { | 328 | free(data); |
| 323 | ret->length = 0; | 329 | data = malloc(length); |
| 324 | free(data); | 330 | if (data == NULL) { |
| 325 | data = malloc(length); | 331 | i = ERR_R_MALLOC_FAILURE; |
| 326 | if (data == NULL) { | 332 | goto err; |
| 327 | i = ERR_R_MALLOC_FAILURE; | ||
| 328 | goto err; | ||
| 329 | } | ||
| 330 | ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
| 331 | } | 333 | } |
| 334 | ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
| 332 | memcpy(data, p, length); | 335 | memcpy(data, p, length); |
| 333 | /* reattach data to object, after which it remains const */ | 336 | /* reattach data to object, after which it remains const */ |
| 334 | ret->data = data; | 337 | ret->data = data; |
