projects
/
oweals
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add additional checks + cleanup
[oweals/openssl.git]
/
apps
/
openssl.c
diff --git
a/apps/openssl.c
b/apps/openssl.c
index 3b4374a0488dd933482e731fb63a0bb34f8b93a7..02d86d546df3e8198bf7d70d18d0aef2ce9281b1 100644
(file)
--- a/
apps/openssl.c
+++ b/
apps/openssl.c
@@
-56,7
+56,7
@@
* [including the GNU Public Licence.]
*/
/* ====================================================================
* [including the GNU Public Licence.]
*/
/* ====================================================================
- * Copyright (c) 1998-200
0
The OpenSSL Project. All rights reserved.
+ * Copyright (c) 1998-200
1
The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@
-114,6
+114,7
@@
#include <string.h>
#include <stdlib.h>
#define OPENSSL_C /* tells apps.h to use complete apps_startup() */
#include <string.h>
#include <stdlib.h>
#define OPENSSL_C /* tells apps.h to use complete apps_startup() */
+#include "apps.h"
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/lhash.h>
#include <openssl/bio.h>
#include <openssl/crypto.h>
#include <openssl/lhash.h>
@@
-121,8
+122,10
@@
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
#define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */
#define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */
-#include "apps.h"
#include "progs.h"
#include "s_apps.h"
#include <openssl/err.h>
#include "progs.h"
#include "s_apps.h"
#include <openssl/err.h>
@@
-138,11
+141,11
@@
static unsigned long MS_CALLBACK hash(const void *a_void);
static int MS_CALLBACK cmp(const void *a_void,const void *b_void);
static LHASH *prog_init(void );
static int do_cmd(LHASH *prog,int argc,char *argv[]);
static int MS_CALLBACK cmp(const void *a_void,const void *b_void);
static LHASH *prog_init(void );
static int do_cmd(LHASH *prog,int argc,char *argv[]);
-LHASH *config=NULL;
char *default_config_file=NULL;
/* Make sure there is only one when MONOLITH is defined */
#ifdef MONOLITH
char *default_config_file=NULL;
/* Make sure there is only one when MONOLITH is defined */
#ifdef MONOLITH
+CONF *config=NULL;
BIO *bio_err=NULL;
#endif
BIO *bio_err=NULL;
#endif
@@
-160,7
+163,7
@@
static void lock_dbg_cb(int mode, int type, const char *file, int line)
goto err;
}
goto err;
}
- if (type < 0 || type > CRYPTO_NUM_LOCKS)
+ if (type < 0 || type >
=
CRYPTO_NUM_LOCKS)
{
errstr = "type out of bounds";
goto err;
{
errstr = "type out of bounds";
goto err;
@@
-214,10
+217,12
@@
static void lock_dbg_cb(int mode, int type, const char *file, int line)
int main(int Argc, char *Argv[])
{
ARGS arg;
int main(int Argc, char *Argv[])
{
ARGS arg;
-#define PROG_NAME_SIZE
16
- char pname[PROG_NAME_SIZE];
+#define PROG_NAME_SIZE
39
+ char pname[PROG_NAME_SIZE
+1
];
FUNCTION f,*fp;
FUNCTION f,*fp;
- MS_STATIC char *prompt,buf[1024],config_name[256];
+ MS_STATIC const char *prompt;
+ MS_STATIC char buf[1024];
+ char *to_free=NULL;
int n,i,ret=0;
int argc;
char **argv,*p;
int n,i,ret=0;
int argc;
char **argv,*p;
@@
-227,12
+232,21
@@
int main(int Argc, char *Argv[])
arg.data=NULL;
arg.count=0;
arg.data=NULL;
arg.count=0;
- if (getenv("OPENSSL_DEBUG_MEMORY") != NULL)
+ if (bio_err == NULL)
+ if ((bio_err=BIO_new(BIO_s_file())) != NULL)
+ BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
+
+ if (getenv("OPENSSL_DEBUG_MEMORY") != NULL) /* if not defined, use compiled-in library defaults */
{
if (!(0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))
{
CRYPTO_malloc_debug_init();
{
if (!(0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))
{
CRYPTO_malloc_debug_init();
- CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
+ CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+ }
+ else
+ {
+ /* OPENSSL_DEBUG_MEMORY=off */
+ CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
}
}
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
}
}
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
@@
-246,36
+260,28
@@
int main(int Argc, char *Argv[])
apps_startup();
apps_startup();
- if (bio_err == NULL)
- if ((bio_err=BIO_new(BIO_s_file())) != NULL)
- BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
-
- ERR_load_crypto_strings();
- ENGINE_load_builtin_engines();
-
/* Lets load up our environment a little */
p=getenv("OPENSSL_CONF");
if (p == NULL)
p=getenv("SSLEAY_CONF");
if (p == NULL)
/* Lets load up our environment a little */
p=getenv("OPENSSL_CONF");
if (p == NULL)
p=getenv("SSLEAY_CONF");
if (p == NULL)
- {
- strcpy(config_name,X509_get_default_cert_area());
-#ifndef OPENSSL_SYS_VMS
- strcat(config_name,"/");
-#endif
- strcat(config_name,OPENSSL_CONF);
- p=config_name;
- }
+ p=to_free=make_config_name();
default_config_file=p;
default_config_file=p;
- config=CONF_load(config,p,&errline);
- if (config == NULL) ERR_clear_error();
+ config=NCONF_new(NULL);
+ i=NCONF_load(config,p,&errline);
+ if (i == 0)
+ {
+ NCONF_free(config);
+ config = NULL;
+ ERR_clear_error();
+ }
prog=prog_init();
/* first check the program name */
prog=prog_init();
/* first check the program name */
- program_name(Argv[0],pname,
PROG_NAME_SIZE
);
+ program_name(Argv[0],pname,
sizeof pname
);
f.name=pname;
fp=(FUNCTION *)lh_retrieve(prog,&f);
f.name=pname;
fp=(FUNCTION *)lh_retrieve(prog,&f);
@@
-303,7
+309,7
@@
int main(int Argc, char *Argv[])
{
ret=0;
p=buf;
{
ret=0;
p=buf;
- n=
1024
;
+ n=
sizeof buf
;
i=0;
for (;;)
{
i=0;
for (;;)
{
@@
-337,20
+343,17
@@
int main(int Argc, char *Argv[])
BIO_printf(bio_err,"bad exit\n");
ret=1;
end:
BIO_printf(bio_err,"bad exit\n");
ret=1;
end:
+ if (to_free)
+ OPENSSL_free(to_free);
if (config != NULL)
{
if (config != NULL)
{
- CONF_free(config);
+
N
CONF_free(config);
config=NULL;
}
if (prog != NULL) lh_free(prog);
if (arg.data != NULL) OPENSSL_free(arg.data);
config=NULL;
}
if (prog != NULL) lh_free(prog);
if (arg.data != NULL) OPENSSL_free(arg.data);
- ERR_remove_state(0);
- EVP_cleanup();
- ERR_free_strings();
-
- ENGINE_cleanup();
- destroy_ui_method();
+ apps_shutdown();
CRYPTO_mem_leaks(bio_err);
if (bio_err != NULL)
CRYPTO_mem_leaks(bio_err);
if (bio_err != NULL)
@@
-358,7
+361,7
@@
end:
BIO_free(bio_err);
bio_err=NULL;
}
BIO_free(bio_err);
bio_err=NULL;
}
- EXIT(ret);
+
OPENSSL_
EXIT(ret);
}
#define LIST_STANDARD_COMMANDS "list-standard-commands"
}
#define LIST_STANDARD_COMMANDS "list-standard-commands"
@@
-486,7
+489,7
@@
static LHASH *prog_init(void)
{
LHASH *ret;
FUNCTION *f;
{
LHASH *ret;
FUNCTION *f;
-
in
t i;
+
size_
t i;
/* Purely so it looks nice when the user hits ? */
for(i=0,f=functions ; f->name != NULL ; ++f,++i)
/* Purely so it looks nice when the user hits ? */
for(i=0,f=functions ; f->name != NULL ; ++f,++i)
@@
-504,12
+507,12
@@
static LHASH *prog_init(void)
/* static int MS_CALLBACK cmp(FUNCTION *a, FUNCTION *b) */
static int MS_CALLBACK cmp(const void *a_void, const void *b_void)
{
/* static int MS_CALLBACK cmp(FUNCTION *a, FUNCTION *b) */
static int MS_CALLBACK cmp(const void *a_void, const void *b_void)
{
- return(strncmp(((FUNCTION *)a_void)->name,
- ((FUNCTION *)b_void)->name,8));
+ return(strncmp(((
const
FUNCTION *)a_void)->name,
+ ((
const
FUNCTION *)b_void)->name,8));
}
/* static unsigned long MS_CALLBACK hash(FUNCTION *a) */
static unsigned long MS_CALLBACK hash(const void *a_void)
{
}
/* static unsigned long MS_CALLBACK hash(FUNCTION *a) */
static unsigned long MS_CALLBACK hash(const void *a_void)
{
- return(lh_strhash(((FUNCTION *)a_void)->name));
+ return(lh_strhash(((
const
FUNCTION *)a_void)->name));
}
}