Fossil SCM

Fix case when trying to free a non-malloced pointer.

linuxfood 2010-03-21 22:38 ssl_platform_fixes
Commit ee59ca74b8b8991520660514266da7483e5f68d7
1 file changed +8 -5
+8 -5
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -86,10 +86,11 @@
8686
** This routine does initial configuration of the SSL module.
8787
*/
8888
void ssl_global_init(void){
8989
if( sslIsInit==0 ){
9090
char *system_store = NULL;
91
+ char *detected_store = NULL;
9192
SSL_library_init();
9293
SSL_load_error_strings();
9394
ERR_load_BIO_strings();
9495
OpenSSL_add_all_algorithms();
9596
sslCtx = SSL_CTX_new(SSLv23_client_method());
@@ -97,26 +98,28 @@
9798
/* TODO Load windows cert store here. */
9899
#elif defined(__linux__)
99100
/* Linux has a few different places to find the root certificate bundle */
100101
if(file_isfile("/etc/pki/tls/cert.pem")) {
101102
/* This is for RedHat derived distros */
102
- system_store = "/etc/pki/tls/cert.pem";
103
+ detected_store = "/etc/pki/tls/cert.pem";
103104
}
104105
else if(file_isfile("/etc/ssl/certs/ca-certificates.crt")) {
105106
/* This is for Debian derived distros, and Arch */
106
- system_store = "/etc/ssl/certs/ca-certificates.crt";
107
+ detected_store = "/etc/ssl/certs/ca-certificates.crt";
107108
}
108109
#elif defined(__FreeBSD__)
109
- system_store = "/usr/local/share/certs/ca-root-nss.crt";
110
+ detected_store = "/usr/local/share/certs/ca-root-nss.crt";
110111
#elif defined(__APPLE__)
111112
/* No action necessary, OpenSSL on OS X appears
112113
to load the system store automatically */
113114
#endif
114
- system_store = db_get("certificate-bundle", system_store);
115
+ system_store = db_get("certificate-bundle", detected_store);
115116
if(system_store != NULL) {
116117
SSL_CTX_load_verify_locations(sslCtx, system_store, NULL);
117
- free(system_store);
118
+ if(detected_store != NULL) {
119
+ free(system_store);
120
+ }
118121
}
119122
sslIsInit = 1;
120123
}
121124
}
122125
123126
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -86,10 +86,11 @@
86 ** This routine does initial configuration of the SSL module.
87 */
88 void ssl_global_init(void){
89 if( sslIsInit==0 ){
90 char *system_store = NULL;
 
91 SSL_library_init();
92 SSL_load_error_strings();
93 ERR_load_BIO_strings();
94 OpenSSL_add_all_algorithms();
95 sslCtx = SSL_CTX_new(SSLv23_client_method());
@@ -97,26 +98,28 @@
97 /* TODO Load windows cert store here. */
98 #elif defined(__linux__)
99 /* Linux has a few different places to find the root certificate bundle */
100 if(file_isfile("/etc/pki/tls/cert.pem")) {
101 /* This is for RedHat derived distros */
102 system_store = "/etc/pki/tls/cert.pem";
103 }
104 else if(file_isfile("/etc/ssl/certs/ca-certificates.crt")) {
105 /* This is for Debian derived distros, and Arch */
106 system_store = "/etc/ssl/certs/ca-certificates.crt";
107 }
108 #elif defined(__FreeBSD__)
109 system_store = "/usr/local/share/certs/ca-root-nss.crt";
110 #elif defined(__APPLE__)
111 /* No action necessary, OpenSSL on OS X appears
112 to load the system store automatically */
113 #endif
114 system_store = db_get("certificate-bundle", system_store);
115 if(system_store != NULL) {
116 SSL_CTX_load_verify_locations(sslCtx, system_store, NULL);
117 free(system_store);
 
 
118 }
119 sslIsInit = 1;
120 }
121 }
122
123
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -86,10 +86,11 @@
86 ** This routine does initial configuration of the SSL module.
87 */
88 void ssl_global_init(void){
89 if( sslIsInit==0 ){
90 char *system_store = NULL;
91 char *detected_store = NULL;
92 SSL_library_init();
93 SSL_load_error_strings();
94 ERR_load_BIO_strings();
95 OpenSSL_add_all_algorithms();
96 sslCtx = SSL_CTX_new(SSLv23_client_method());
@@ -97,26 +98,28 @@
98 /* TODO Load windows cert store here. */
99 #elif defined(__linux__)
100 /* Linux has a few different places to find the root certificate bundle */
101 if(file_isfile("/etc/pki/tls/cert.pem")) {
102 /* This is for RedHat derived distros */
103 detected_store = "/etc/pki/tls/cert.pem";
104 }
105 else if(file_isfile("/etc/ssl/certs/ca-certificates.crt")) {
106 /* This is for Debian derived distros, and Arch */
107 detected_store = "/etc/ssl/certs/ca-certificates.crt";
108 }
109 #elif defined(__FreeBSD__)
110 detected_store = "/usr/local/share/certs/ca-root-nss.crt";
111 #elif defined(__APPLE__)
112 /* No action necessary, OpenSSL on OS X appears
113 to load the system store automatically */
114 #endif
115 system_store = db_get("certificate-bundle", detected_store);
116 if(system_store != NULL) {
117 SSL_CTX_load_verify_locations(sslCtx, system_store, NULL);
118 if(detected_store != NULL) {
119 free(system_store);
120 }
121 }
122 sslIsInit = 1;
123 }
124 }
125
126

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button