Coder Social home page Coder Social logo

zettabgp's Issues

panic in BmpMessage::decode_from

thread 'main' panicked at 'range end index 3 out of range for slice of length 1', /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/afi/ipv6.rs:158:40
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::slice::index::slice_end_index_len_fail_rt
   3: core::slice::index::slice_end_index_len_fail
   4: <core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index
             at /build/rustc-1.65.0-src/library/core/src/slice/index.rs:316:13
   5: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /build/rustc-1.65.0-src/library/core/src/slice/index.rs:18:9
   6: zettabgp::afi::ipv6::BgpAddrV6::from_bits
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/afi/ipv6.rs:158:40
   7: <zettabgp::afi::ipv6::BgpAddrV6 as zettabgp::afi::BgpItem<zettabgp::afi::ipv6::BgpAddrV6>>::extract_bits_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/afi/ipv6.rs:198:9
   8: zettabgp::afi::decode_bgpitem_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/afi/mod.rs:198:13
   9: zettabgp::afi::decode_bgpitems_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/afi/mod.rs:205:20
  10: zettabgp::afi::BgpAddrs::decode_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/afi/mod.rs:933:37
  11: zettabgp::message::attributes::multiproto::BgpMPUpdates::decode_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/message/attributes/multiproto.rs:143:18
  12: zettabgp::message::attributes::BgpAttrItem::decode_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/message/attributes/mod.rs:115:45
  13: <zettabgp::message::update::BgpUpdateMessage as zettabgp::BgpMessage>::decode_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/message/update/mod.rs:162:29
  14: zettabgp::bmp::msgrmon::BmpMessageRouteMonitoring::decode_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/bmp/msgrmon.rs:41:9
  15: zettabgp::bmp::BmpMessage::decode_from
             at /home/yuka/.cargo/registry/src/github.com-1ecc6299db9ec823/zettabgp-0.3.0/src/bmp/mod.rs:75:17
  16: fernglas::bmp_collector::run::{{closure}}::{{closure}}
             at ./src/bmp_collector.rs:61:33

The input:

00000000  03 00 00 00 8d 00 00 80  00 00 00 00 00 00 00 00  |................|
00000010  2a 0e b9 40 00 00 00 02  00 00 00 00 00 00 00 20  |*..@........... |
00000020  00 03 2e 0b 2d 8b 8a 14  63 bf ee a1 00 00 2a ff  |....-...c.....*.|
00000030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff 00  |................|
00000040  5d 02 00 00 00 46 40 01  01 00 40 02 0a 02 02 00  |]....F@...@.....|
00000050  00 fd e9 00 00 fd e9 40  05 04 00 00 00 64 90 0e  |[email protected]..|
00000060  00 2a 00 02 01 10 2a 0e  b9 40 00 00 00 02 00 00  |.*....*..@......|
00000070  00 00 00 00 00 12 00 00  00 00 07 80 2a 0e b9 40  |............*..@|
00000080  00 00 00 00 00 00 00 00  00 00 13 35              |...........5|
0000008c

proposed patch:

diff --git a/src/afi/ipv6.rs b/src/afi/ipv6.rs
index e7fec7c..374e5c6 100644
--- a/src/afi/ipv6.rs
+++ b/src/afi/ipv6.rs
@@ -138,7 +138,8 @@ impl BgpAddrV6 {
         self.addr.octets()[0] == 255
     }
     pub fn from_bits(bits: u8, buf: &[u8]) -> Result<(BgpAddrV6, usize), BgpError> {
-        if bits > 128 {
+        let bytes = ((bits + 7) / 8) as usize;
+        if bits > 128 || buf.len() < bytes {
             return Err(BgpError::from_string(format!(
                 "Invalid FEC length: {:?}",
                 bits
@@ -154,7 +155,6 @@ impl BgpAddrV6 {
                 0,
             ));
         }
-        let bytes = ((bits + 7) / 8) as usize;
         bf[0..bytes].clone_from_slice(&buf[0..bytes]);
         Ok((
             BgpAddrV6 {

Feature request: use log crate

Currently there are many println or eprintln statements in the code, which can be confusing to users of an application using the zettabgp library.
It would be wonderful if these could be switched to log::info! and log::warn! statements, which can be filtered by the application.
If you like this idea, I could prepare a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.