fix crash: RPC "createmultisig" and "addmultisigaddress" #5706

pull fsb4000 wants to merge 1 commits into bitcoin:master from fsb4000:patch-2 changing 1 files +2 −0
  1. fsb4000 commented at 12:31 PM on January 25, 2015: contributor

    Bug description:

    1. Open Bitcoin-Qt(or bitcoind)
    2. Open "Debug window"
    3. Enter
    createmultisig 17 '["0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014"]'
    

    or

    addmultisigaddress 17 '["0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014","0227d09df34a6eca0e2009663d2f0c6edc97314f78f308f53b7c8ffa7c552c1014"]' "bug"
    
    1. Result createmultisig or addmultisigaddress

    About the fix:

    1. function _createmultisig_redeemScriptCScript has line (file src/rpcmisc.cpp)
    result = GetScriptForMultisig(nRequired, pubkeys);
    
    1. function GetScriptForMultisig has lines (file src/script/standard.cpp)
    script << CScript::EncodeOP_N(nRequired);
    

    and

    script << CScript::EncodeOP_N(keys.size()) << OP_CHECKMULTISIG;
    
    1. function EncodeOP_N has the assert(file src/script/script.h)
    assert(n >= 0 && n <= 16);
    
    1. We don't need check nRequired because it checks here:
    if ((int)keys.size() < nRequired)
            throw runtime_error(
                strprintf("not enough keys supplied "
                          "(got %" PRIszu " keys, but need at least %d to redeem)", keys.size(), nRequired));
    
    1. English is not my native, so ,maybe, error message should be improved...

    similar to https://github.com/novacoin-project/novacoin/pull/125

  2. fix crash: createmultisig and addmultisigaddress e5d9d77df2
  3. laanwj added the label Bug on Jan 26, 2015
  4. laanwj added the label Priority Medium on Jan 26, 2015
  5. laanwj added the label RPC on Jan 26, 2015
  6. laanwj commented at 10:48 AM on January 26, 2015: member

    Thanks for reporting this in such detail. I'm not sure this limitation is intended, so we may go for a different fix.

  7. luke-jr commented at 10:51 AM on January 26, 2015: member

    Pretty sure it should fail with >15 due to the P2SH limitations.

  8. laanwj commented at 11:03 AM on January 26, 2015: member

    Right, I remember now, we already check the resulting script against MAX_SCRIPT_ELEMENT_SIZE for that later.

    The issue is that some assertion before that fails while constructing the script

    In any case, the proposed fix to hardcode a limit at 16 (because the underlying code fails) is not so bad then. Though it may make sense to move the check down to GetScriptForMultisig instead of in the RPC code, so that potential other usages of it get a clear error.

  9. fsb4000 commented at 11:03 AM on January 26, 2015: contributor

    luke-jr:

    Pretty sure it should fail with >15 due to the P2SH limitations.

    Yes, it should. if keys.size equal 16 then error message looks like:

    redeemScript exceeds size limit: 547 > 520 (code -1)
    

    But I left a restriction on 16 because

    static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
    

    may change in the future

  10. luke-jr commented at 11:59 AM on January 26, 2015: member

    Not likely, that'd be a hardfork.

  11. fsb4000 closed this on Feb 8, 2015

  12. fsb4000 deleted the branch on Feb 8, 2015
  13. fsb4000 restored the branch on Feb 8, 2015
  14. fsb4000 reopened this on Feb 8, 2015

  15. laanwj merged this on Feb 20, 2015
  16. laanwj closed this on Feb 20, 2015

  17. laanwj referenced this in commit a026a56c4e on Feb 20, 2015
  18. laanwj referenced this in commit 7f502be259 on Feb 20, 2015
  19. fsb4000 deleted the branch on Mar 11, 2015
  20. reddink referenced this in commit 9d5eb81c42 on May 27, 2020
  21. 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-13 15:15 UTC

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