rib: limit route prefix length in rib/register command

refs #4262

Change-Id: I567934419f6872cb0f5a823400f53014b9c6e85e
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index 71a7cf3..ba89719 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -28,6 +28,7 @@
 #include "readvertise/client-to-nlsr-readvertise-policy.hpp"
 #include "readvertise/nfd-rib-readvertise-destination.hpp"
 
+#include "core/fib-max-depth.hpp"
 #include "core/logger.hpp"
 #include "core/scheduler.hpp"
 
@@ -198,6 +199,12 @@
                           ControlParameters parameters,
                           const ndn::mgmt::CommandContinuation& done)
 {
+  if (parameters.getName().size() > FIB_MAX_DEPTH) {
+    done(ControlResponse(414, "Route prefix cannot exceed " + ndn::to_string(FIB_MAX_DEPTH) +
+                              " components"));
+    return;
+  }
+
   setFaceForSelfRegistration(interest, parameters);
 
   // Respond since command is valid and authorized