From 6f4fc6ad20643ff6ae69f88c2a5581f79dc3a2c5 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Thu, 7 Sep 2017 17:33:03 +0200
Subject: [PATCH] [fix] Have a maximum endpoint length

---
 app/lib/common-libs/parsers/peer.ts | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/app/lib/common-libs/parsers/peer.ts b/app/lib/common-libs/parsers/peer.ts
index 485dec1d0..3da9da509 100644
--- a/app/lib/common-libs/parsers/peer.ts
+++ b/app/lib/common-libs/parsers/peer.ts
@@ -49,7 +49,8 @@ export class PeerParser extends GenericParser {
       'BAD_PORT': 155,
       'BAD_FINGERPRINT': 156,
       'BAD_BLOCK': 157,
-      'NO_IP_GIVEN': 158
+      'NO_IP_GIVEN': 158,
+      'TOO_LONG_ENDPOINT': 159
     };
     if(!err){
       // Version
@@ -66,6 +67,14 @@ export class PeerParser extends GenericParser {
       if(!obj.block)
         err = {code: codes.BAD_BLOCK, message: "Incorrect Block field"};
     }
+    if(!err){
+      // Endpoint length
+      for (const ep of (obj.endpoints || [])) {
+        if (!err && ep.length > 255) {
+          err = {code: codes.TOO_LONG_ENDPOINT, message: "An endpoint has maximum 255 characters length."}
+        }
+      }
+    }
     // Basic Merkled API requirements
     let bma = obj.getBMA();
     if(!err){
-- 
GitLab