static int dlfcn_load(DSO *dso) { void *ptr = NULL; /* See applicable comments in dso_dl.c */ char *filename = DSO_convert_filename(dso, NULL); int flags = DLOPEN_FLAG; if (filename == NULL) { DSOerr(DSO_F_DLFCN_LOAD, DSO_R_NO_FILENAME); goto err; } # ifdef RTLD_GLOBAL if (dso->flags & DSO_FLAG_GLOBAL_SYMBOLS) flags |= RTLD_GLOBAL; # endif ptr = dlopen(filename, flags); if (ptr == NULL) { DSOerr(DSO_F_DLFCN_LOAD, DSO_R_LOAD_FAILED); ERR_add_error_data(4, "filename(", filename, "): ", dlerror()); goto err; } if (!sk_void_push(dso->meth_data, (char *)ptr)) { DSOerr(DSO_F_DLFCN_LOAD, DSO_R_STACK_ERROR); goto err; } /* Success */ dso->loaded_filename = filename; return (1); err: /* Cleanup! */ OPENSSL_free(filename); if (ptr != NULL) dlclose(ptr); return (0); }
static int win32_unload(DSO *dso) { HINSTANCE *p; if (dso == NULL) { DSOerr(DSO_F_WIN32_UNLOAD, ERR_R_PASSED_NULL_PARAMETER); return (0); } if (sk_void_num(dso->meth_data) < 1) return (1); p = sk_void_pop(dso->meth_data); if (p == NULL) { DSOerr(DSO_F_WIN32_UNLOAD, DSO_R_NULL_HANDLE); return (0); } if (!FreeLibrary(*p)) { DSOerr(DSO_F_WIN32_UNLOAD, DSO_R_UNLOAD_FAILED); /* * We should push the value back onto the stack in case of a retry. */ sk_void_push(dso->meth_data, p); return (0); } /* Cleanup */ OPENSSL_free(p); return (1); }
static int dlfcn_unload(DSO *dso) { return 0; #if 0 void *ptr; if (dso == NULL) { DSOerr(DSO_F_DLFCN_UNLOAD, ERR_R_PASSED_NULL_PARAMETER); return (0); } if (sk_void_num(dso->meth_data) < 1) return (1); ptr = sk_void_pop(dso->meth_data); if (ptr == NULL) { DSOerr(DSO_F_DLFCN_UNLOAD, DSO_R_NULL_HANDLE); /* * Should push the value back onto the stack in case of a retry. */ sk_void_push(dso->meth_data, ptr); return (0); } /* For now I'm not aware of any errors associated with dlclose() */ dlclose(ptr); return (1); #endif }
static int win32_load(DSO *dso) { HINSTANCE h = NULL, *p = NULL; /* See applicable comments from dso_dl.c */ char *filename = DSO_convert_filename(dso, NULL); if(filename == NULL) { DSOerr(DSO_F_WIN32_LOAD,DSO_R_NO_FILENAME); goto err; } h = LoadLibraryA(filename); if(h == NULL) { DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED); ERR_add_error_data(3, "filename(", filename, ")"); goto err; } p = (HINSTANCE *)OPENSSL_malloc(sizeof(HINSTANCE)); if(p == NULL) { DSOerr(DSO_F_WIN32_LOAD,ERR_R_MALLOC_FAILURE); goto err; } *p = h; if(!sk_void_push(dso->meth_data, p)) { DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR); goto err; } /* Success */ dso->loaded_filename = filename; return(1); err: /* Cleanup !*/ if(filename != NULL) OPENSSL_free(filename); if(p != NULL) OPENSSL_free(p); if(h != NULL) FreeLibrary(h); return(0); }
/* * For a given CRYPTO_EX_DATA variable, set the value corresponding to a * particular index in the class used by this variable */ int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val) { int i; if (ad->sk == NULL) { if ((ad->sk = sk_void_new_null()) == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, ERR_R_MALLOC_FAILURE); return 0; } } for (i = sk_void_num(ad->sk); i <= idx; ++i) { if (!sk_void_push(ad->sk, NULL)) { CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, ERR_R_MALLOC_FAILURE); return 0; } } sk_void_set(ad->sk, idx, val); return 1; }
int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int index, void *val) { int n, i; if (ad->sk == NULL) { ad->sk = sk_void_new_null(); if (ad->sk == NULL) { OPENSSL_PUT_ERROR(CRYPTO, CRYPTO_set_ex_data, ERR_R_MALLOC_FAILURE); return 0; } } n = sk_void_num(ad->sk); /* Add NULL values until the stack is long enough. */ for (i = n; i <= index; i++) { if (!sk_void_push(ad->sk, NULL)) { OPENSSL_PUT_ERROR(CRYPTO, CRYPTO_set_ex_data, ERR_R_MALLOC_FAILURE); return 0; } } sk_void_set(ad->sk, index, val); return 1; }
static int vms_load(DSO *dso) { void *ptr = NULL; /* See applicable comments in dso_dl.c */ char *filename = DSO_convert_filename(dso, NULL); /* Ensure 32-bit pointer for "p", and appropriate malloc() function. */ # if __INITIAL_POINTER_SIZE == 64 # define DSO_MALLOC _malloc32 # pragma pointer_size save # pragma pointer_size 32 # else /* __INITIAL_POINTER_SIZE == 64 */ # define DSO_MALLOC OPENSSL_malloc # endif /* __INITIAL_POINTER_SIZE == 64 [else] */ DSO_VMS_INTERNAL *p = NULL; # if __INITIAL_POINTER_SIZE == 64 # pragma pointer_size restore # endif /* __INITIAL_POINTER_SIZE == 64 */ const char *sp1, *sp2; /* Search result */ const char *ext = NULL; /* possible extension to add */ if (filename == NULL) { DSOerr(DSO_F_VMS_LOAD, DSO_R_NO_FILENAME); goto err; } /*- * A file specification may look like this: * * node::dev:[dir-spec]name.type;ver * * or (for compatibility with TOPS-20): * * node::dev:<dir-spec>name.type;ver * * and the dir-spec uses '.' as separator. Also, a dir-spec * may consist of several parts, with mixed use of [] and <>: * * [dir1.]<dir2> * * We need to split the file specification into the name and * the rest (both before and after the name itself). */ /* * Start with trying to find the end of a dir-spec, and save the position * of the byte after in sp1 */ sp1 = strrchr(filename, ']'); sp2 = strrchr(filename, '>'); if (sp1 == NULL) sp1 = sp2; if (sp2 != NULL && sp2 > sp1) sp1 = sp2; if (sp1 == NULL) sp1 = strrchr(filename, ':'); if (sp1 == NULL) sp1 = filename; else sp1++; /* The byte after the found character */ /* Now, let's see if there's a type, and save the position in sp2 */ sp2 = strchr(sp1, '.'); /* * If there is a period and the next character is a semi-colon, * we need to add an extension */ if (sp2 != NULL && sp2[1] == ';') ext = ".EXE"; /* * If we found it, that's where we'll cut. Otherwise, look for a version * number and save the position in sp2 */ if (sp2 == NULL) { sp2 = strchr(sp1, ';'); ext = ".EXE"; } /* * If there was still nothing to find, set sp2 to point at the end of the * string */ if (sp2 == NULL) sp2 = sp1 + strlen(sp1); /* Check that we won't get buffer overflows */ if (sp2 - sp1 > FILENAME_MAX || (sp1 - filename) + strlen(sp2) > FILENAME_MAX) { DSOerr(DSO_F_VMS_LOAD, DSO_R_FILENAME_TOO_BIG); goto err; } p = DSO_MALLOC(sizeof(DSO_VMS_INTERNAL)); if (p == NULL) { DSOerr(DSO_F_VMS_LOAD, ERR_R_MALLOC_FAILURE); goto err; } strncpy(p->filename, sp1, sp2 - sp1); p->filename[sp2 - sp1] = '\0'; strncpy(p->imagename, filename, sp1 - filename); p->imagename[sp1 - filename] = '\0'; if (ext) { strcat(p->imagename, ext); if (*sp2 == '.') sp2++; } strcat(p->imagename, sp2); p->filename_dsc.dsc$w_length = strlen(p->filename); p->filename_dsc.dsc$b_dtype = DSC$K_DTYPE_T; p->filename_dsc.dsc$b_class = DSC$K_CLASS_S; p->filename_dsc.dsc$a_pointer = p->filename; p->imagename_dsc.dsc$w_length = strlen(p->imagename); p->imagename_dsc.dsc$b_dtype = DSC$K_DTYPE_T; p->imagename_dsc.dsc$b_class = DSC$K_CLASS_S; p->imagename_dsc.dsc$a_pointer = p->imagename; if (!sk_void_push(dso->meth_data, (char *)p)) { DSOerr(DSO_F_VMS_LOAD, DSO_R_STACK_ERROR); goto err; } /* Success (for now, we lie. We actually do not know...) */ dso->loaded_filename = filename; return (1); err: /* Cleanup! */ if (p != NULL) OPENSSL_free(p); if (filename != NULL) OPENSSL_free(filename); return (0); }