Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-9185

Add checks for random generator for uint64 in cppsuite

    XMLWordPrintableJSON

Details

    • 3
    • Storage - Ra 2022-05-16

    Description

      In the cppsuite, we use our random_generator to generate numbers using the generate_integer function at different places. There are places where it might be dangerous and lead to unexpected behavior, see this example in the update_operation function of the database_operation class:

              /* Choose a random key to update. */
              uint64_t key_id =
                random_generator::instance().generate_integer<uint64_t>(0, coll.get_key_count() - 1); 

      The function get_key_count returns a uint64_t, if this one is 0, we end up choosing among the whole uint64_t range which is not what we expect.

      The goal of this ticket is to check where we generate random numbers and make sure it is safe. Suggested changes would be something along those lines:

      -          random_generator::instance().generate_integer<uint64_t>(0, coll.get_key_count() - 1);
      +          random_generator::instance().generate_integer<uint64_t>(0, coll.get_key_count() > 0 ? coll.get_key_count() - 1 : 0);

      Attachments

        Activity

          People

            ruby.chen@mongodb.com Ruby Chen
            etienne.petrel@mongodb.com Etienne Petrel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: