Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: openssl/crypto/engine/eng_dyn.c

Issue 9254031: Upgrade chrome's OpenSSL to same version Android ships with. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/openssl/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « openssl/crypto/engine/eng_cryptodev.c ('k') | openssl/crypto/engine/eng_err.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* crypto/engine/eng_dyn.c */ 1 /* crypto/engine/eng_dyn.c */
2 /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2 /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
5 /* ==================================================================== 5 /* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 * ENGINE list. If 2, the add must succeed or the entire load should fai l. */ 139 * ENGINE list. If 2, the add must succeed or the entire load should fai l. */
140 int list_add_value; 140 int list_add_value;
141 /* The symbol name for the version checking function */ 141 /* The symbol name for the version checking function */
142 const char *DYNAMIC_F1; 142 const char *DYNAMIC_F1;
143 /* The symbol name for the "initialise ENGINE structure" function */ 143 /* The symbol name for the "initialise ENGINE structure" function */
144 const char *DYNAMIC_F2; 144 const char *DYNAMIC_F2;
145 /* Whether to never use 'dirs', use 'dirs' as a fallback, or only use 145 /* Whether to never use 'dirs', use 'dirs' as a fallback, or only use
146 * 'dirs' for loading. Default is to use 'dirs' as a fallback. */ 146 * 'dirs' for loading. Default is to use 'dirs' as a fallback. */
147 int dir_load; 147 int dir_load;
148 /* A stack of directories from which ENGINEs could be loaded */ 148 /* A stack of directories from which ENGINEs could be loaded */
149 » STACK *dirs; 149 » STACK_OF(OPENSSL_STRING) *dirs;
150 }; 150 };
151 151
152 /* This is the "ex_data" index we obtain and reserve for use with our context 152 /* This is the "ex_data" index we obtain and reserve for use with our context
153 * structure. */ 153 * structure. */
154 static int dynamic_ex_data_idx = -1; 154 static int dynamic_ex_data_idx = -1;
155 155
156 static void int_free_str(void *s) { OPENSSL_free(s); } 156 static void int_free_str(char *s) { OPENSSL_free(s); }
157 /* Because our ex_data element may or may not get allocated depending on whether 157 /* Because our ex_data element may or may not get allocated depending on whether
158 * a "first-use" occurs before the ENGINE is freed, we have a memory leak 158 * a "first-use" occurs before the ENGINE is freed, we have a memory leak
159 * problem to solve. We can't declare a "new" handler for the ex_data as we 159 * problem to solve. We can't declare a "new" handler for the ex_data as we
160 * don't want a dynamic_data_ctx in *all* ENGINE structures of all types (this 160 * don't want a dynamic_data_ctx in *all* ENGINE structures of all types (this
161 * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free" 161 * is a bug in the design of CRYPTO_EX_DATA). As such, we just declare a "free"
162 * handler and that will get called if an ENGINE is being destroyed and there 162 * handler and that will get called if an ENGINE is being destroyed and there
163 * was an ex_data element corresponding to our context type. */ 163 * was an ex_data element corresponding to our context type. */
164 static void dynamic_data_ctx_free_func(void *parent, void *ptr, 164 static void dynamic_data_ctx_free_func(void *parent, void *ptr,
165 CRYPTO_EX_DATA *ad, int idx, long argl, void *argp) 165 CRYPTO_EX_DATA *ad, int idx, long argl, void *argp)
166 { 166 {
167 if(ptr) 167 if(ptr)
168 { 168 {
169 dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr; 169 dynamic_data_ctx *ctx = (dynamic_data_ctx *)ptr;
170 if(ctx->dynamic_dso) 170 if(ctx->dynamic_dso)
171 DSO_free(ctx->dynamic_dso); 171 DSO_free(ctx->dynamic_dso);
172 if(ctx->DYNAMIC_LIBNAME) 172 if(ctx->DYNAMIC_LIBNAME)
173 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME); 173 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
174 if(ctx->engine_id) 174 if(ctx->engine_id)
175 OPENSSL_free((void*)ctx->engine_id); 175 OPENSSL_free((void*)ctx->engine_id);
176 if(ctx->dirs) 176 if(ctx->dirs)
177 » » » sk_pop_free(ctx->dirs, int_free_str); 177 » » » sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str);
178 OPENSSL_free(ctx); 178 OPENSSL_free(ctx);
179 } 179 }
180 } 180 }
181 181
182 /* Construct the per-ENGINE context. We create it blindly and then use a lock to 182 /* Construct the per-ENGINE context. We create it blindly and then use a lock to
183 * check for a race - if so, all but one of the threads "racing" will have 183 * check for a race - if so, all but one of the threads "racing" will have
184 * wasted their time. The alternative involves creating everything inside the 184 * wasted their time. The alternative involves creating everything inside the
185 * lock which is far worse. */ 185 * lock which is far worse. */
186 static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) 186 static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
187 { 187 {
188 dynamic_data_ctx *c; 188 dynamic_data_ctx *c;
189 c = OPENSSL_malloc(sizeof(dynamic_data_ctx)); 189 c = OPENSSL_malloc(sizeof(dynamic_data_ctx));
190 if(!c) 190 if(!c)
191 { 191 {
192 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); 192 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
193 return 0; 193 return 0;
194 } 194 }
195 memset(c, 0, sizeof(dynamic_data_ctx)); 195 memset(c, 0, sizeof(dynamic_data_ctx));
196 c->dynamic_dso = NULL; 196 c->dynamic_dso = NULL;
197 c->v_check = NULL; 197 c->v_check = NULL;
198 c->bind_engine = NULL; 198 c->bind_engine = NULL;
199 c->DYNAMIC_LIBNAME = NULL; 199 c->DYNAMIC_LIBNAME = NULL;
200 c->no_vcheck = 0; 200 c->no_vcheck = 0;
201 c->engine_id = NULL; 201 c->engine_id = NULL;
202 c->list_add_value = 0; 202 c->list_add_value = 0;
203 c->DYNAMIC_F1 = "v_check"; 203 c->DYNAMIC_F1 = "v_check";
204 c->DYNAMIC_F2 = "bind_engine"; 204 c->DYNAMIC_F2 = "bind_engine";
205 c->dir_load = 1; 205 c->dir_load = 1;
206 » c->dirs = sk_new_null(); 206 » c->dirs = sk_OPENSSL_STRING_new_null();
207 if(!c->dirs) 207 if(!c->dirs)
208 { 208 {
209 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); 209 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
210 OPENSSL_free(c); 210 OPENSSL_free(c);
211 return 0; 211 return 0;
212 } 212 }
213 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 213 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
214 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, 214 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
215 dynamic_ex_data_idx)) == NULL) 215 dynamic_ex_data_idx)) == NULL)
216 { 216 {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 return 0; 386 return 0;
387 } 387 }
388 { 388 {
389 char *tmp_str = BUF_strdup(p); 389 char *tmp_str = BUF_strdup(p);
390 if(!tmp_str) 390 if(!tmp_str)
391 { 391 {
392 ENGINEerr(ENGINE_F_DYNAMIC_CTRL, 392 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
393 ERR_R_MALLOC_FAILURE); 393 ERR_R_MALLOC_FAILURE);
394 return 0; 394 return 0;
395 } 395 }
396 » » sk_insert(ctx->dirs, tmp_str, -1); 396 » » sk_OPENSSL_STRING_insert(ctx->dirs, tmp_str, -1);
397 } 397 }
398 return 1; 398 return 1;
399 default: 399 default:
400 break; 400 break;
401 } 401 }
402 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED); 402 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
403 return 0; 403 return 0;
404 } 404 }
405 405
406 static int int_load(dynamic_data_ctx *ctx) 406 static int int_load(dynamic_data_ctx *ctx)
407 { 407 {
408 int num, loop; 408 int num, loop;
409 /* Unless told not to, try a direct load */ 409 /* Unless told not to, try a direct load */
410 if((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso, 410 if((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso,
411 ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL) 411 ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL)
412 return 1; 412 return 1;
413 /* If we're not allowed to use 'dirs' or we have none, fail */ 413 /* If we're not allowed to use 'dirs' or we have none, fail */
414 » if(!ctx->dir_load || ((num = sk_num(ctx->dirs)) < 1)) 414 » if(!ctx->dir_load || (num = sk_OPENSSL_STRING_num(ctx->dirs)) < 1)
415 return 0; 415 return 0;
416 for(loop = 0; loop < num; loop++) 416 for(loop = 0; loop < num; loop++)
417 { 417 {
418 » » const char *s = sk_value(ctx->dirs, loop); 418 » » const char *s = sk_OPENSSL_STRING_value(ctx->dirs, loop);
419 char *merge = DSO_merge(ctx->dynamic_dso, ctx->DYNAMIC_LIBNAME, s); 419 char *merge = DSO_merge(ctx->dynamic_dso, ctx->DYNAMIC_LIBNAME, s);
420 if(!merge) 420 if(!merge)
421 return 0; 421 return 0;
422 if(DSO_load(ctx->dynamic_dso, merge, NULL, 0)) 422 if(DSO_load(ctx->dynamic_dso, merge, NULL, 0))
423 { 423 {
424 /* Found what we're looking for */ 424 /* Found what we're looking for */
425 OPENSSL_free(merge); 425 OPENSSL_free(merge);
426 return 1; 426 return 1;
427 } 427 }
428 OPENSSL_free(merge); 428 OPENSSL_free(merge);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 ENGINEerr(ENGINE_F_DYNAMIC_LOAD, 539 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
540 ENGINE_R_CONFLICTING_ENGINE_ID); 540 ENGINE_R_CONFLICTING_ENGINE_ID);
541 return 0; 541 return 0;
542 } 542 }
543 /* Tolerate */ 543 /* Tolerate */
544 ERR_clear_error(); 544 ERR_clear_error();
545 } 545 }
546 } 546 }
547 return 1; 547 return 1;
548 } 548 }
OLDNEW
« no previous file with comments | « openssl/crypto/engine/eng_cryptodev.c ('k') | openssl/crypto/engine/eng_err.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698