Browse Source

bitcoin: add len arg to pubkey conversion function.

Our json parser doesn't give nul-terminated strings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
cf547d491b
  1. 4
      bitcoin/pubkey.c
  2. 2
      bitcoin/pubkey.h
  3. 2
      test-cli/create-anchor-tx.c
  4. 2
      test-cli/create-commit-spend-tx.c
  5. 2
      test-cli/create-htlc-spend-tx.c
  6. 2
      test-cli/create-steal-tx.c
  7. 4
      test-cli/open-channel.c

4
bitcoin/pubkey.c

@ -72,9 +72,9 @@ fail_free_secpctx:
return false;
}
bool pubkey_from_hexstr(const char *derstr, struct pubkey *key)
bool pubkey_from_hexstr(const char *derstr, size_t slen, struct pubkey *key)
{
size_t slen = strlen(derstr), dlen;
size_t dlen;
unsigned char der[65];
dlen = hex_data_size(slen);

2
bitcoin/pubkey.h

@ -15,7 +15,7 @@ struct pubkey {
};
/* Convert from hex string of DER (scriptPubKey from validateaddress) */
bool pubkey_from_hexstr(const char *derstr, struct pubkey *key);
bool pubkey_from_hexstr(const char *derstr, size_t derlen, struct pubkey *key);
/* Pubkey from privkey */
bool pubkey_from_privkey(const struct privkey *privkey,

2
test-cli/create-anchor-tx.c

@ -142,7 +142,7 @@ int main(int argc, char *argv[])
if (change) {
struct pubkey change_key;
if (!pubkey_from_hexstr(argv[4], &change_key))
if (!pubkey_from_hexstr(argv[4], strlen(argv[4]), &change_key))
errx(1, "Invalid change key %s", argv[3]);
redeemscript = bitcoin_redeem_single(anchor, &change_key);

2
test-cli/create-commit-spend-tx.c

@ -73,7 +73,7 @@ int main(int argc, char *argv[])
if (!testnet)
errx(1, "Private key '%s' not on testnet!", argv[5]);
if (!pubkey_from_hexstr(argv[6], &outpubkey))
if (!pubkey_from_hexstr(argv[6], strlen(argv[6]), &outpubkey))
errx(1, "Invalid bitcoin pubkey '%s'", argv[6]);
/* Get pubkeys */

2
test-cli/create-htlc-spend-tx.c

@ -93,7 +93,7 @@ int main(int argc, char *argv[])
if (!testnet)
errx(1, "Private key '%s' not on testnet!", argv[6]);
if (!pubkey_from_hexstr(argv[7], &outpubkey))
if (!pubkey_from_hexstr(argv[7], strlen(argv[7]), &outpubkey))
errx(1, "Invalid commit key '%s'", argv[7]);
/* Get pubkeys */

2
test-cli/create-steal-tx.c

@ -73,7 +73,7 @@ int main(int argc, char *argv[])
if (!proto_to_rel_locktime(o1->delay, &locktime))
errx(1, "Invalid locktime in o2");
if (!pubkey_from_hexstr(argv[6], &outpubkey))
if (!pubkey_from_hexstr(argv[6], strlen(argv[6]), &outpubkey))
errx(1, "Invalid bitcoin pubkey '%s'", argv[6]);
/* Get pubkeys */

4
test-cli/open-channel.c

@ -69,10 +69,10 @@ int main(int argc, char *argv[])
if (!hex_decode(argv[1], strlen(argv[1]), &seed, sizeof(seed)))
errx(1, "Invalid seed '%s' - need 256 hex bits", argv[1]);
if (!pubkey_from_hexstr(argv[2], &commitkey))
if (!pubkey_from_hexstr(argv[2], strlen(argv[2]), &commitkey))
errx(1, "Invalid commit key '%s'", argv[2]);
if (!pubkey_from_hexstr(argv[3], &finalkey))
if (!pubkey_from_hexstr(argv[3], strlen(argv[3]), &finalkey))
errx(1, "Invalid final key '%s'", argv[3]);
if (offer_anchor && min_confirms == 0)

Loading…
Cancel
Save