]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Enforces sig_rec length in message_signing
authorSergi Delgado Segura <sergi.delgado.s@gmail.com>
Tue, 20 Jul 2021 09:05:47 +0000 (11:05 +0200)
committerSergi Delgado Segura <sergi.delgado.s@gmail.com>
Tue, 20 Jul 2021 09:41:38 +0000 (11:41 +0200)
lightning/src/util/message_signing.rs

index 2055b4087749ada5b3baef731770608baceb629e..8beff835a4bffe1f0b3d59e672380323b6164f98 100644 (file)
@@ -36,6 +36,11 @@ fn sigrec_encode(sig_rec: RecoverableSignature) -> Vec<u8> {
 }
 
 fn sigrec_decode(sig_rec: Vec<u8>) -> Result<RecoverableSignature, Error> {
+    // Signature must be 64 + 1 bytes long (compact signature + recovery id)
+    if sig_rec.len() != 65 {
+        return Err(Error::InvalidSignature);
+    }
+
     let rsig = &sig_rec[1..];
     let rid = sig_rec[0] as i32 - 31;