Fix crash in Address::from_str if input isn't long enough
This commit is contained in:
parent
8ae711ce0f
commit
855b377d51
|
@ -241,8 +241,9 @@ impl FromStr for Address {
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Address, Error> {
|
fn from_str(s: &str) -> Result<Address, Error> {
|
||||||
// bech32 (note that upper or lowercase is allowed but NOT mixed case)
|
// bech32 (note that upper or lowercase is allowed but NOT mixed case)
|
||||||
if &s.as_bytes()[0..3] == b"bc1" || &s.as_bytes()[0..3] == b"tb1" ||
|
if s.len() >= 3 &&
|
||||||
&s.as_bytes()[0..3] == b"BC1" || &s.as_bytes()[0..3] == b"TB1" {
|
(&s.as_bytes()[0..3] == b"bc1" || &s.as_bytes()[0..3] == b"tb1" ||
|
||||||
|
&s.as_bytes()[0..3] == b"BC1" || &s.as_bytes()[0..3] == b"TB1") {
|
||||||
let witprog = try!(WitnessProgram::from_address(s));
|
let witprog = try!(WitnessProgram::from_address(s));
|
||||||
let network = match witprog.network() {
|
let network = match witprog.network() {
|
||||||
bitcoin_bech32::constants::Network::Bitcoin => Network::Bitcoin,
|
bitcoin_bech32::constants::Network::Bitcoin => Network::Bitcoin,
|
||||||
|
|
Loading…
Reference in New Issue