BadPractise: assert may bypass function calls when NDEBUG is defined #3168

issue imzhuli opened this issue on October 27, 2013
  1. imzhuli commented at 4:36 PM on October 27, 2013: none

    key.cpp:

    151 void SetSecretBytes(const unsigned char vch[32]) { 152 BIGNUM bn; 153 BN_init(&bn); 154 assert(BN_bin2bn(vch, 32, &bn)); 155 assert(EC_KEY_regenerate_key(pkey, &bn)); 156 BN_clear_free(&bn); 157 }

  2. laanwj commented at 7:02 AM on October 28, 2013: member

    This is a known issue and it exists in multiple places.

    For fatal errors that are impossible to handle normally (for example because it implies some internal state was corrupted) we should add a sanity check function that cannot be disabled instead of asserts.

  3. Diapolo commented at 2:37 PM on November 4, 2013: none

    This seems to be rather important then...

  4. laanwj commented at 4:03 PM on November 4, 2013: member

    We don't support building with NDEBUG at all at the moment.

  5. sipa commented at 4:51 PM on November 4, 2013: member

    I think we could use a

    bool fAssertsEnabled = false;
    assert((fAssertsEnabled = true));
    if (!fAssertsEnabled)
       exit in some fatal way;
    
  6. laanwj commented at 9:32 AM on March 31, 2014: member

    A quick grep for assert shows that we're no longer doing anything with (obvious) side-effects in an assert anymore. So I'm closing this.

    I'd still recommend keeping assertions enabled because a lot of important conditions are checked using assert. You'd reduce security and robustness significantly by disabling them.

  7. laanwj closed this on Mar 31, 2014

  8. Bushstar referenced this in commit df3dbe85b7 on Apr 8, 2020
  9. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 00:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me