Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2021, The University of Memphis, |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Ashlesh Gawande | 5d93aa5 | 2020-06-13 18:57:45 -0700 | [diff] [blame^] | 20 | */ |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 21 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 22 | #include "nlsr.hpp" |
| 23 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 24 | #include "../test-common.hpp" |
| 25 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 26 | namespace nlsr { |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 27 | namespace test { |
| 28 | |
| 29 | class AdvertiseCrashFixture : public nlsr::test::UnitTestTimeFixture |
| 30 | { |
| 31 | public: |
| 32 | AdvertiseCrashFixture() |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 33 | : face(m_ioService, m_keyChain, {true, true}) |
Saurab Dulal | 427e012 | 2019-11-28 11:58:02 -0600 | [diff] [blame] | 34 | , conf(face, m_keyChain) |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 35 | , confProcessor(conf) |
| 36 | , nlsr(face, m_keyChain, conf) |
| 37 | , namePrefixList(conf.getNamePrefixList()) |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 38 | { |
| 39 | // Add an adjacency to nlsr |
| 40 | Adjacent adj("/ndn/edu/test-site-2/%C1.Router/test", |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 41 | ndn::FaceUri("udp://1.0.0.2"), 10, Adjacent::STATUS_INACTIVE, 0, 0); |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 42 | conf.getAdjacencyList().insert(adj); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 43 | |
| 44 | // Create a face dataset response with the face having the same uri as |
| 45 | // the adjacent |
| 46 | ndn::nfd::FaceStatus payload1; |
| 47 | payload1.setFaceId(25401); |
| 48 | payload1.setRemoteUri("udp://1.0.0.2"); |
| 49 | |
| 50 | std::vector<ndn::nfd::FaceStatus> faces{payload1}; |
| 51 | |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 52 | addIdentity(conf.getRouterPrefix()); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 53 | |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 54 | // Simulate a callback with fake response |
| 55 | // This will trigger the undefined behavior found |
| 56 | // in fib.cpp if an operation is done on non-existent faceUri |
| 57 | nlsr.processFaceDataset(faces); |
| 58 | |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 59 | this->advanceClocks(ndn::time::milliseconds(1), 10); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 60 | |
| 61 | face.sentInterests.clear(); |
| 62 | } |
| 63 | |
| 64 | public: |
| 65 | ndn::util::DummyClientFace face; |
Ashlesh Gawande | 85998a1 | 2017-12-07 22:22:13 -0600 | [diff] [blame] | 66 | ConfParameter conf; |
| 67 | DummyConfFileProcessor confProcessor; |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 68 | |
| 69 | Nlsr nlsr; |
| 70 | NamePrefixList& namePrefixList; |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | BOOST_FIXTURE_TEST_CASE(TestAdvertiseCrash, AdvertiseCrashFixture) |
| 74 | { |
| 75 | // Note that this test does not setup any security |
| 76 | // and the interest will be rejected by NLSR. |
| 77 | // This is because the bug triggers upon merely receiving |
| 78 | // an advertise interest so security was not needed. |
| 79 | |
| 80 | // Advertise |
| 81 | ndn::nfd::ControlParameters parameters; |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 82 | parameters.setName("/prefix/to/advertise"); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 83 | ndn::Name advertiseCommand("/localhost/nlsr/prefix-update/advertise"); |
| 84 | advertiseCommand.append(parameters.wireEncode()); |
| 85 | |
Junxiao Shi | 008c9b1 | 2019-01-13 23:15:56 +0000 | [diff] [blame] | 86 | auto advertiseInterest = std::make_shared<ndn::Interest>(advertiseCommand); |
| 87 | advertiseInterest->setCanBePrefix(false); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 88 | face.receive(*advertiseInterest); |
Muktadir Chowdhury | f04f989 | 2017-08-20 20:42:56 -0500 | [diff] [blame] | 89 | this->advanceClocks(ndn::time::milliseconds(10), 10); |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | } // namespace test |
Ashlesh Gawande | 793e870 | 2017-08-01 15:59:26 -0500 | [diff] [blame] | 93 | } // namespace nlsr |