Skip to content

Commit 40b7d7e

Browse files
committed
forbid unsafe
1 parent cd8f1de commit 40b7d7e

File tree

6 files changed

+10
-16
lines changed

6 files changed

+10
-16
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Safety Dance](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
2+
13
Rust-Lightning, not Rusty's Lightning!
24
=====
35

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! instead of having a rather-separate lightning appendage to a wallet.
1111
1212
#![cfg_attr(not(feature = "fuzztarget"), deny(missing_docs))]
13+
#![forbid(unsafe_code)]
1314

1415
extern crate bitcoin;
1516
extern crate bitcoin_hashes;

src/ln/msgs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ pub trait RoutingMessageHandler : Send + Sync {
696696
fn get_next_node_announcements(&self, starting_point: Option<&PublicKey>, batch_amount: u8) -> Vec<NodeAnnouncement>;
697697
}
698698

699+
#[derive(Default, Clone)]
699700
pub(crate) struct OnionRealm0HopData {
700701
pub(crate) short_channel_id: u64,
701702
pub(crate) amt_to_forward: u64,
@@ -708,12 +709,12 @@ mod fuzzy_internal_msgs {
708709
// them from untrusted input):
709710

710711
use super::OnionRealm0HopData;
712+
#[derive(Default, Clone)]
711713
pub struct OnionHopData {
712714
pub(crate) realm: u8,
713715
pub(crate) data: OnionRealm0HopData,
714716
pub(crate) hmac: [u8; 32],
715717
}
716-
unsafe impl ::util::internal_traits::NoDealloc for OnionHopData{}
717718

718719
pub struct DecodedOnionErrorPacket {
719720
pub(crate) hmac: [u8; 32],

src/ln/onion_utils.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ln::channelmanager::{PaymentHash, HTLCSource};
22
use ln::msgs;
33
use ln::router::{Route,RouteHop};
4-
use util::{byte_utils, internal_traits};
4+
use util::byte_utils;
55
use util::chacha20::ChaCha20;
66
use util::errors::{self, APIError};
77
use util::ser::{Readable, Writeable};
@@ -17,9 +17,9 @@ use secp256k1::Secp256k1;
1717
use secp256k1::ecdh::SharedSecret;
1818
use secp256k1;
1919

20-
use std::ptr;
2120
use std::io::Cursor;
2221
use std::sync::Arc;
22+
use ln::msgs::OnionHopData;
2323

2424
pub(super) struct OnionKeys {
2525
#[cfg(test)]
@@ -113,9 +113,7 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) ->
113113
let mut cur_value_msat = 0u64;
114114
let mut cur_cltv = starting_htlc_offset;
115115
let mut last_short_channel_id = 0;
116-
let mut res: Vec<msgs::OnionHopData> = Vec::with_capacity(route.hops.len());
117-
internal_traits::test_no_dealloc::<msgs::OnionHopData>(None);
118-
unsafe { res.set_len(route.hops.len()); }
116+
let mut res: Vec<msgs::OnionHopData> = vec![OnionHopData::default(); route.hops.len()];
119117

120118
for (idx, hop) in route.hops.iter().enumerate().rev() {
121119
// First hop gets special values so that it can check, on receipt, that everything is
@@ -147,8 +145,8 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) ->
147145

148146
#[inline]
149147
fn shift_arr_right(arr: &mut [u8; 20*65]) {
150-
unsafe {
151-
ptr::copy(arr[0..].as_ptr(), arr[65..].as_mut_ptr(), 19*65);
148+
for i in (65..20*65).rev () {
149+
arr[i] = arr[i-65];
152150
}
153151
for i in 0..65 {
154152
arr[i] = 0;

src/util/internal_traits.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/util/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub(crate) mod chacha20;
99
#[cfg(not(feature = "fuzztarget"))]
1010
pub(crate) mod poly1305;
1111
pub(crate) mod chacha20poly1305rfc;
12-
pub(crate) mod internal_traits;
1312
pub(crate) mod transaction_utils;
1413

1514
#[macro_use]

0 commit comments

Comments
 (0)