[GH-ISSUE #2090] segfault running without self test #1396

Closed
opened 2026-10-14 03:47:50 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @crioux on GitHub (Mar 16, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2090

Originally assigned to: @magnumripper on GitHub.

Running without self test causes this line to not run:

            struct db_main *test_db = 0;
            char *where;

            if ( (options.flags & FLG_NOTESTS) == 0)
                test_db = ldr_init_test_db(database.format, &database);

So test_db is NULL, then when it gets to opencl_nt_fmt_plug.c:reset()
there is a straight dereference of db that crashes:

    num_loaded_hashes = db->salts->count;

any other places in the various hashes that don't expect a null db would also have this issue.

Originally created by @crioux on GitHub (Mar 16, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2090 Originally assigned to: @magnumripper on GitHub. Running without self test causes this line to not run: ``` struct db_main *test_db = 0; char *where; if ( (options.flags & FLG_NOTESTS) == 0) test_db = ldr_init_test_db(database.format, &database); ``` So test_db is NULL, then when it gets to opencl_nt_fmt_plug.c:reset() there is a straight dereference of db that crashes: ``` num_loaded_hashes = db->salts->count; ``` any other places in the various hashes that don't expect a null db would also have this issue.
bsakaguchi 2026-10-14 03:47:50 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@crioux commented on GitHub (Mar 16, 2016):

I dont see why a patch like this isn't sufficient. It's a sledgehammer, but if you're skipping tests, why do some part of the tests at all?



diff --git a/src/john.c b/src/john.c
index 1bd3f64..278c9dc 100644
--- a/src/john.c
+++ b/src/john.c
@@ -1644,17 +1644,20 @@ static void john_run(void)

                if (!(options.flags & FLG_STDOUT)) {
                        struct db_main *test_db = 0;
-                       char *where;
+                       char *where = NULL;

-                       if ( (options.flags & FLG_NOTESTS) == 0)
+                       if ((options.flags & FLG_NOTESTS) == 0)
+                       {
                                test_db = ldr_init_test_db(database.format, &database);
-                       where = fmt_self_test(database.format, test_db);
-                       ldr_free_test_db(test_db);
-                       if (where) {
-                               fprintf(stderr, "Self test failed (%s)\n",
-                                   where);
-                               error();
+                               where = fmt_self_test(database.format, test_db);
+                               ldr_free_test_db(test_db);
+                               if (where) {
+                                       fprintf(stderr, "Self test failed (%s)\n",
+                                       where);
+                                       error();
+                               }
                        }
+
                        trigger_reset = 1;
                        log_init(LOG_NAME, options.activepot,
                                 options.session);
<!-- gh-comment-id:197142988 --> @crioux commented on GitHub (Mar 16, 2016): I dont see why a patch like this isn't sufficient. It's a sledgehammer, but if you're skipping tests, why do some part of the tests at all? ``` diff --git a/src/john.c b/src/john.c index 1bd3f64..278c9dc 100644 --- a/src/john.c +++ b/src/john.c @@ -1644,17 +1644,20 @@ static void john_run(void) if (!(options.flags & FLG_STDOUT)) { struct db_main *test_db = 0; - char *where; + char *where = NULL; - if ( (options.flags & FLG_NOTESTS) == 0) + if ((options.flags & FLG_NOTESTS) == 0) + { test_db = ldr_init_test_db(database.format, &database); - where = fmt_self_test(database.format, test_db); - ldr_free_test_db(test_db); - if (where) { - fprintf(stderr, "Self test failed (%s)\n", - where); - error(); + where = fmt_self_test(database.format, test_db); + ldr_free_test_db(test_db); + if (where) { + fprintf(stderr, "Self test failed (%s)\n", + where); + error(); + } } + trigger_reset = 1; log_init(LOG_NAME, options.activepot, options.session); ```
Author
Owner

@magnumripper commented on GitHub (Mar 16, 2016):

Thanks, this is a known bug and I'll have a look at some solution similar to your patch within a few days. I was hoping @Sayantan2048 would be back in business by now but apparently it will take some more time.

<!-- gh-comment-id:197222581 --> @magnumripper commented on GitHub (Mar 16, 2016): Thanks, this is a known bug and I'll have a look at some solution similar to your patch within a few days. I was hoping @Sayantan2048 would be back in business by now but apparently it will take some more time.
Author
Owner

@magnumripper commented on GitHub (Mar 16, 2016):

@jfoug introduced this bug with a362940b for issue #1967. The patch is very weird, obviously incorrect.

<!-- gh-comment-id:197223842 --> @magnumripper commented on GitHub (Mar 16, 2016): @jfoug introduced this bug with a362940b for issue #1967. The patch is very weird, obviously incorrect.
Author
Owner

@magnumripper commented on GitHub (Mar 16, 2016):

Apparently I approved that patch so I am to blame too 😎

<!-- gh-comment-id:197224368 --> @magnumripper commented on GitHub (Mar 16, 2016): Apparently I approved that patch so I am to blame too :sunglasses:
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#1396
No description provided.