Ticket #19566: bug_shared_random_patch_r1.patch

File bug_shared_random_patch_r1.patch, 2.5 KB (added by neel, 2 years ago)

Patch to replace tor_assert() with BUG() in SR code whenever possible

  • src/or/shared_random.c

    From d77a1cae97190ce0682d3c0c2e59b1f58f0744fd Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Tue, 12 Sep 2017 15:53:28 -0400
    Subject: [PATCH] Switch to BUG() in SR (shared random) code (partially)
    
    ---
     src/or/shared_random.c       |  3 ++-
     src/or/shared_random_state.c | 18 ++++++++++++------
     2 files changed, 14 insertions(+), 7 deletions(-)
    
    diff --git a/src/or/shared_random.c b/src/or/shared_random.c
    index e4ee64139..09c891115 100644
    a b sr_compute_srv(void) 
    976976  /* Computing a shared random value in the commit phase is very wrong. This
    977977   * should only happen at the very end of the reveal phase when a new
    978978   * protocol run is about to start. */
    979   tor_assert(sr_state_get_phase() == SR_PHASE_REVEAL);
     979  if (BUG(sr_state_get_phase() == SR_PHASE_REVEAL))
     980    return;
    980981  state_commits = sr_state_get_commits();
    981982
    982983  commits = smartlist_new();
  • src/or/shared_random_state.c

    diff --git a/src/or/shared_random_state.c b/src/or/shared_random_state.c
    index 5fcf88cc4..75dfb2f43 100644
    a b disk_state_update(void) 
    654654{
    655655  config_line_t **next, *line;
    656656
    657   tor_assert(sr_disk_state);
    658   tor_assert(sr_state);
     657  if (BUG(sr_disk_state))
     658    return;
     659  if (BUG(sr_state))
     660    return;
    659661
    660662  /* Reset current disk state. */
    661663  disk_state_reset();
    disk_state_save_to_disk(void) 
    819821STATIC void
    820822reset_state_for_new_protocol_run(time_t valid_after)
    821823{
    822   tor_assert(sr_state);
     824  if (BUG(sr_state))
     825    return;
    823826
    824827  /* Keep counters in track */
    825828  sr_state->n_reveal_rounds = 0;
    sr_state_update(time_t valid_after) 
    11511154{
    11521155  sr_phase_t next_phase;
    11531156
    1154   tor_assert(sr_state);
     1157  if (BUG(sr_state))
     1158    return;
    11551159
    11561160  /* Don't call this function twice in the same voting period. */
    11571161  if (valid_after <= sr_state->valid_after) {
    sr_state_update(time_t valid_after) 
    11901194  /* Count the current round */
    11911195  if (sr_state->phase == SR_PHASE_COMMIT) {
    11921196    /* invariant check: we've not entered reveal phase yet */
    1193     tor_assert(sr_state->n_reveal_rounds == 0);
     1197    if (BUG(sr_state->n_reveal_rounds == 0))
     1198      return;
    11941199    sr_state->n_commit_rounds++;
    11951200  } else {
    11961201    sr_state->n_reveal_rounds++;
    sr_state_init(int save_to_disk, int read_from_disk) 
    13801385void
    13811386set_sr_phase(sr_phase_t phase)
    13821387{
    1383   tor_assert(sr_state);
     1388  if (BUG(sr_state))
     1389    return;
    13841390  sr_state->phase = phase;
    13851391}
    13861392