Fix ASAN reported bug
authorAngelo Failla <pallotron@fb.com>
Tue, 18 Apr 2017 07:10:48 +0000 (00:10 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 18 Apr 2017 07:19:51 +0000 (00:19 -0700)
Reviewed By: yfeldblum

Differential Revision: D4898404

fbshipit-source-id: 82256ae3dcd76444dc1b192d3bb6d50f142cee81

folly/IPAddressV6.cpp

index c7a93ef..57d00aa 100644 (file)
@@ -186,14 +186,14 @@ IPAddressV6 IPAddressV6::fromInverseArpaName(const std::string& arpaname) {
     throw IPAddressFormatException(sformat("Invalid input. Got '{}'", piece));
   }
   std::array<char, IPAddressV6::kToFullyQualifiedSize> ip;
-  int pos = 0;
+  size_t pos = 0;
   int count = 0;
   for (int p = pieces.size() - 1; p >= 0; p--) {
     ip[pos] = pieces[p][0];
     pos++;
     count++;
     // add ':' every 4 chars
-    if (count == 4) {
+    if (count == 4 && pos < ip.size()) {
       ip[pos++] = ':';
       count = 0;
     }