BUG OF THE MONTH | Strange loop

V612 An unconditional ‘return’ within a loop. crypter.cpp 169

bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn)
    if (!SetCrypted())
      return false;

    CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin();
    for (; mi != mapCryptedKeys.end(); ++mi)
      const CPubKey &vchPubKey = (*mi).second.first;
      const std::vector<unsigned char> &vchCryptedSecret =
      CKeyingMaterial vchSecret;
      if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret,
                        vchPubKey.GetHash(), vchSecret))
          return false;
      if (vchSecret.size() != 32)
          return false;
      CKey key;
      key.Set(vchSecret.begin(), vchSecret.end(),
      if (key.GetPubKey() == vchPubKey)
      return false; 
    vMasterKey = vMasterKeyIn;
  return true;

Notice the loop: it must iterate through some keys. However, the loop body executes only once. There is the return false operator at the end of the loop, and it can also be terminated by the break operator. At the same time, there is not a single continue operator to be found.

Please click here to see more bugs from this project.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.