summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormiod <>2014-09-28 10:50:33 +0000
committermiod <>2014-09-28 10:50:33 +0000
commitb486c9d0043a8b4a2b8bc2005c207b48fd310242 (patch)
tree9c5f5b5e201df6f69a6835a1a72734723914591f /src
parent9db6a5b9d7bcae094827d75a94a39b0626456b92 (diff)
downloadopenbsd-b486c9d0043a8b4a2b8bc2005c207b48fd310242.tar.gz
openbsd-b486c9d0043a8b4a2b8bc2005c207b48fd310242.tar.bz2
openbsd-b486c9d0043a8b4a2b8bc2005c207b48fd310242.zip
Someone (TM) thought it was smart to save memory by using malloc(1) and
manual field fiddling to create an ASN1_INTEGER object, instead of using M_ASN1_INTEGER_new() which will allocate sizeof(long) bytes. That person had probably never looked into malloc(3) and never heard of allocation size rounding. Thus, replace the obfuscated code with M_ASN1_INTEGER_new() followed by ASN1_INTEGER_set(), to achieve a similar result, without the need for /* version == 0 */ comments. ok bcook@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/x509/x509_req.c9
-rw-r--r--src/lib/libssl/src/crypto/x509/x509_req.c9
2 files changed, 8 insertions, 10 deletions
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index 22d2124614..452ce0a512 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_req.c,v 1.15 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: x509_req.c,v 1.16 2014/09/28 10:50:33 miod 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 *
@@ -86,11 +86,10 @@ X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
86 86
87 ri = ret->req_info; 87 ri = ret->req_info;
88 88
89 ri->version->length = 1; 89 if ((ri->version = M_ASN1_INTEGER_new()) == NULL)
90 ri->version->data = malloc(1); 90 goto err;
91 if (ri->version->data == NULL) 91 if (ASN1_INTEGER_set(ri->version, 0) == 0)
92 goto err; 92 goto err;
93 ri->version->data[0] = 0; /* version == 0 */
94 93
95 if (!X509_REQ_set_subject_name(ret, X509_get_subject_name(x))) 94 if (!X509_REQ_set_subject_name(ret, X509_get_subject_name(x)))
96 goto err; 95 goto err;
diff --git a/src/lib/libssl/src/crypto/x509/x509_req.c b/src/lib/libssl/src/crypto/x509/x509_req.c
index 22d2124614..452ce0a512 100644
--- a/src/lib/libssl/src/crypto/x509/x509_req.c
+++ b/src/lib/libssl/src/crypto/x509/x509_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_req.c,v 1.15 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: x509_req.c,v 1.16 2014/09/28 10:50:33 miod 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 *
@@ -86,11 +86,10 @@ X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
86 86
87 ri = ret->req_info; 87 ri = ret->req_info;
88 88
89 ri->version->length = 1; 89 if ((ri->version = M_ASN1_INTEGER_new()) == NULL)
90 ri->version->data = malloc(1); 90 goto err;
91 if (ri->version->data == NULL) 91 if (ASN1_INTEGER_set(ri->version, 0) == 0)
92 goto err; 92 goto err;
93 ri->version->data[0] = 0; /* version == 0 */
94 93
95 if (!X509_REQ_set_subject_name(ret, X509_get_subject_name(x))) 94 if (!X509_REQ_set_subject_name(ret, X509_get_subject_name(x)))
96 goto err; 95 goto err;