From 62284f79b1321b060d61eb1c98093c28cf87593f Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 12 Oct 2016 14:56:53 +0200 Subject: [PATCH] Get rid of exit() in hashcat.c --- include/hashcat.h | 4 ++-- src/hashcat.c | 6 ++++-- src/main.c | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/hashcat.h b/include/hashcat.h index 3953cecd0..ed47ab4a4 100644 --- a/include/hashcat.h +++ b/include/hashcat.h @@ -6,9 +6,9 @@ #ifndef _HASHCAT_H #define _HASHCAT_H -int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime); +int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime); -void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)); +int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)); void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx); #endif // _HASHCAT_H diff --git a/src/hashcat.c b/src/hashcat.c index c3aff6a30..e12f95c5a 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -55,13 +55,13 @@ extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_CNT; extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_BUF[]; -void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)) +int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)) { if (event == NULL) { fprintf (stderr, "Event callback function is mandatory\n"); - exit (-1); + return -1; } hashcat_ctx->event = event; @@ -92,6 +92,8 @@ void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, str hashcat_ctx->user_options_extra = (user_options_extra_t *) hcmalloc (hashcat_ctx, sizeof (user_options_extra_t)); hashcat_ctx->user_options = (user_options_t *) hcmalloc (hashcat_ctx, sizeof (user_options_t)); hashcat_ctx->wl_data = (wl_data_t *) hcmalloc (hashcat_ctx, sizeof (wl_data_t)); + + return 0; } void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx) diff --git a/src/main.c b/src/main.c index d062d9141..7e1d40585 100644 --- a/src/main.c +++ b/src/main.c @@ -489,7 +489,9 @@ int main (int argc, char **argv) hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); - hashcat_ctx_init (hashcat_ctx, event); + const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event); + + if (rc_hashcat_init == -1) return -1; // initialize the session via getops for commandline use or // alternatively you can set the user_options directly