Skip to content

Commit bdbf566

Browse files
tamasblummerTheBlueMatt
authored andcommitted
forbid unsafe
1 parent cd8f1de commit bdbf566

File tree

6 files changed

+8
-17
lines changed

6 files changed

+8
-17
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ mod fuzzy_internal_msgs {
713713
pub(crate) data: OnionRealm0HopData,
714714
pub(crate) hmac: [u8; 32],
715715
}
716-
unsafe impl ::util::internal_traits::NoDealloc for OnionHopData{}
717716

718717
pub struct DecodedOnionErrorPacket {
719718
pub(crate) hmac: [u8; 32],

src/ln/onion_utils.rs

Lines changed: 5 additions & 8 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,7 +17,6 @@ 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;
2322

@@ -114,24 +113,22 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) ->
114113
let mut cur_cltv = starting_htlc_offset;
115114
let mut last_short_channel_id = 0;
116115
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()); }
119116

120117
for (idx, hop) in route.hops.iter().enumerate().rev() {
121118
// First hop gets special values so that it can check, on receipt, that everything is
122119
// exactly as it should be (and the next hop isn't trying to probe to find out if we're
123120
// the intended recipient).
124121
let value_msat = if cur_value_msat == 0 { hop.fee_msat } else { cur_value_msat };
125122
let cltv = if cur_cltv == starting_htlc_offset { hop.cltv_expiry_delta + starting_htlc_offset } else { cur_cltv };
126-
res[idx] = msgs::OnionHopData {
123+
res.insert(0, msgs::OnionHopData {
127124
realm: 0,
128125
data: msgs::OnionRealm0HopData {
129126
short_channel_id: last_short_channel_id,
130127
amt_to_forward: value_msat,
131128
outgoing_cltv_value: cltv,
132129
},
133130
hmac: [0; 32],
134-
};
131+
});
135132
cur_value_msat += hop.fee_msat;
136133
if cur_value_msat >= 21000000 * 100000000 * 1000 {
137134
return Err(APIError::RouteError{err: "Channel fees overflowed?!"});
@@ -147,8 +144,8 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) ->
147144

148145
#[inline]
149146
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);
147+
for i in (65..20*65).rev() {
148+
arr[i] = arr[i-65];
152149
}
153150
for i in 0..65 {
154151
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)