diff options
| author | 2013-11-06 20:14:42 +0100 | |
|---|---|---|
| committer | 2013-11-06 20:14:42 +0100 | |
| commit | 763896dd2592cbc980cac8e63841202620c078f6 (patch) | |
| tree | fb9b64a0227d6afc56e04c876c7fc312fbaa0ddd /common/userpref.c | |
| parent | 7777aeb11aa33cadd694c7b9131bbac94d789a1a (diff) | |
| download | libimobiledevice-763896dd2592cbc980cac8e63841202620c078f6.tar.gz libimobiledevice-763896dd2592cbc980cac8e63841202620c078f6.tar.bz2 | |
userpref: fix incorrect use of BIO_get_mem_data() when generating keys (closing #32)
Diffstat (limited to 'common/userpref.c')
| -rw-r--r-- | common/userpref.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/common/userpref.c b/common/userpref.c index 8af4cdf..0d32f9e 100644 --- a/common/userpref.c +++ b/common/userpref.c | |||
| @@ -782,22 +782,47 @@ static userpref_error_t userpref_device_record_gen_keys_and_cert(const char* udi | |||
| 782 | 782 | ||
| 783 | if (root_cert && root_pkey && host_cert && host_pkey) { | 783 | if (root_cert && root_pkey && host_cert && host_pkey) { |
| 784 | BIO* membp; | 784 | BIO* membp; |
| 785 | char *bdata; | ||
| 785 | 786 | ||
| 786 | membp = BIO_new(BIO_s_mem()); | 787 | membp = BIO_new(BIO_s_mem()); |
| 787 | if (PEM_write_bio_X509(membp, root_cert) > 0) { | 788 | if (PEM_write_bio_X509(membp, root_cert) > 0) { |
| 788 | root_cert_pem.size = BIO_get_mem_data(membp, &root_cert_pem.data); | 789 | root_cert_pem.size = BIO_get_mem_data(membp, &bdata); |
| 790 | root_cert_pem.data = (unsigned char*)malloc(root_cert_pem.size); | ||
| 791 | if (root_cert_pem.data) { | ||
| 792 | memcpy(root_cert_pem.data, bdata, root_cert_pem.size); | ||
| 793 | } | ||
| 794 | BIO_free(membp); | ||
| 795 | membp = NULL; | ||
| 789 | } | 796 | } |
| 790 | membp = BIO_new(BIO_s_mem()); | 797 | membp = BIO_new(BIO_s_mem()); |
| 791 | if (PEM_write_bio_PrivateKey(membp, root_pkey, NULL, NULL, 0, 0, NULL) > 0) { | 798 | if (PEM_write_bio_PrivateKey(membp, root_pkey, NULL, NULL, 0, 0, NULL) > 0) { |
| 792 | root_key_pem.size = BIO_get_mem_data(membp, &root_key_pem.data); | 799 | root_key_pem.size = BIO_get_mem_data(membp, &bdata); |
| 800 | root_key_pem.data = (unsigned char*)malloc(root_key_pem.size); | ||
| 801 | if (root_key_pem.data) { | ||
| 802 | memcpy(root_key_pem.data, bdata, root_key_pem.size); | ||
| 803 | } | ||
| 804 | BIO_free(membp); | ||
| 805 | membp = NULL; | ||
| 793 | } | 806 | } |
| 794 | membp = BIO_new(BIO_s_mem()); | 807 | membp = BIO_new(BIO_s_mem()); |
| 795 | if (PEM_write_bio_X509(membp, host_cert) > 0) { | 808 | if (PEM_write_bio_X509(membp, host_cert) > 0) { |
| 796 | host_cert_pem.size = BIO_get_mem_data(membp, &host_cert_pem.data); | 809 | host_cert_pem.size = BIO_get_mem_data(membp, &bdata); |
| 810 | host_cert_pem.data = (unsigned char*)malloc(host_cert_pem.size); | ||
| 811 | if (host_cert_pem.data) { | ||
| 812 | memcpy(host_cert_pem.data, bdata, host_cert_pem.size); | ||
| 813 | } | ||
| 814 | BIO_free(membp); | ||
| 815 | membp = NULL; | ||
| 797 | } | 816 | } |
| 798 | membp = BIO_new(BIO_s_mem()); | 817 | membp = BIO_new(BIO_s_mem()); |
| 799 | if (PEM_write_bio_PrivateKey(membp, host_pkey, NULL, NULL, 0, 0, NULL) > 0) { | 818 | if (PEM_write_bio_PrivateKey(membp, host_pkey, NULL, NULL, 0, 0, NULL) > 0) { |
| 800 | host_key_pem.size = BIO_get_mem_data(membp, &host_key_pem.data); | 819 | host_key_pem.size = BIO_get_mem_data(membp, &bdata); |
| 820 | host_key_pem.data = (unsigned char*)malloc(host_key_pem.size); | ||
| 821 | if (host_key_pem.data) { | ||
| 822 | memcpy(host_key_pem.data, bdata, host_key_pem.size); | ||
| 823 | } | ||
| 824 | BIO_free(membp); | ||
| 825 | membp = NULL; | ||
| 801 | } | 826 | } |
| 802 | } | 827 | } |
| 803 | 828 | ||
