Dont unwrap `RouteParameter::expiry_time` as users can set it
authorMatt Corallo <git@bluematt.me>
Wed, 27 Oct 2021 22:12:07 +0000 (22:12 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 30 Oct 2021 01:53:19 +0000 (01:53 +0000)
Users can provide anything they want as `RouteParameters` so we
shouldn't assume any fields are set any particular way, including
`expiry_time` set at all.

lightning-invoice/src/payment.rs

index 68b06faa0ecf6456a8c311e7a50cd5ce35412e76..b706deaddd2a728a0898fbc8d2323233d2ebfcbf 100644 (file)
@@ -313,8 +313,9 @@ fn expiry_time_from_unix_epoch(invoice: &Invoice) -> Duration {
 }
 
 fn has_expired(params: &RouteParameters) -> bool {
-       let expiry_time = Duration::from_secs(params.payee.expiry_time.unwrap());
-       Invoice::is_expired_from_epoch(&SystemTime::UNIX_EPOCH, expiry_time)
+       if let Some(expiry_time) = params.payee.expiry_time {
+               Invoice::is_expired_from_epoch(&SystemTime::UNIX_EPOCH, Duration::from_secs(expiry_time))
+       } else { false }
 }
 
 impl<P: Deref, R, S: Deref, L: Deref, E> EventHandler for InvoicePayer<P, R, S, L, E>