mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
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>
This commit is contained in:
@@ -72,9 +72,9 @@ fail_free_secpctx:
|
|||||||
return false;
|
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];
|
unsigned char der[65];
|
||||||
|
|
||||||
dlen = hex_data_size(slen);
|
dlen = hex_data_size(slen);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ struct pubkey {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Convert from hex string of DER (scriptPubKey from validateaddress) */
|
/* 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 */
|
/* Pubkey from privkey */
|
||||||
bool pubkey_from_privkey(const struct privkey *privkey,
|
bool pubkey_from_privkey(const struct privkey *privkey,
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ int main(int argc, char *argv[])
|
|||||||
if (change) {
|
if (change) {
|
||||||
struct pubkey change_key;
|
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]);
|
errx(1, "Invalid change key %s", argv[3]);
|
||||||
|
|
||||||
redeemscript = bitcoin_redeem_single(anchor, &change_key);
|
redeemscript = bitcoin_redeem_single(anchor, &change_key);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
|
|||||||
if (!testnet)
|
if (!testnet)
|
||||||
errx(1, "Private key '%s' not on testnet!", argv[5]);
|
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]);
|
errx(1, "Invalid bitcoin pubkey '%s'", argv[6]);
|
||||||
|
|
||||||
/* Get pubkeys */
|
/* Get pubkeys */
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ int main(int argc, char *argv[])
|
|||||||
if (!testnet)
|
if (!testnet)
|
||||||
errx(1, "Private key '%s' not on testnet!", argv[6]);
|
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]);
|
errx(1, "Invalid commit key '%s'", argv[7]);
|
||||||
|
|
||||||
/* Get pubkeys */
|
/* Get pubkeys */
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
|
|||||||
if (!proto_to_rel_locktime(o1->delay, &locktime))
|
if (!proto_to_rel_locktime(o1->delay, &locktime))
|
||||||
errx(1, "Invalid locktime in o2");
|
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]);
|
errx(1, "Invalid bitcoin pubkey '%s'", argv[6]);
|
||||||
|
|
||||||
/* Get pubkeys */
|
/* Get pubkeys */
|
||||||
|
|||||||
@@ -69,10 +69,10 @@ int main(int argc, char *argv[])
|
|||||||
if (!hex_decode(argv[1], strlen(argv[1]), &seed, sizeof(seed)))
|
if (!hex_decode(argv[1], strlen(argv[1]), &seed, sizeof(seed)))
|
||||||
errx(1, "Invalid seed '%s' - need 256 hex bits", argv[1]);
|
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]);
|
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]);
|
errx(1, "Invalid final key '%s'", argv[3]);
|
||||||
|
|
||||||
if (offer_anchor && min_confirms == 0)
|
if (offer_anchor && min_confirms == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user