debugd: Fix an off-by-one error with PATH_MAX

If the path is as long as PATH_MAX then its nul terminator will exceed
the limit. Correct this.

BUG=chromium:1085464
TEST=FEATURES=test emerge-nami debugd

Change-Id: I4be35b0e5248f3180efbdcc344f767d5f1452908
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2240210
Tested-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: Paul Moy <pmoy@chromium.org>
diff --git a/debugd/src/helper_utils.cc b/debugd/src/helper_utils.cc
index 76dadb9..6294d6e 100644
--- a/debugd/src/helper_utils.cc
+++ b/debugd/src/helper_utils.cc
@@ -5,6 +5,7 @@
 #include "debugd/src/helper_utils.h"
 
 #include <inttypes.h>
+#include <limits.h>
 #include <vector>
 
 #include <base/strings/stringprintf.h>
@@ -16,7 +17,7 @@
   std::string path =
       base::StringPrintf("%s/%s", helpers_dir, relative_path.c_str());
 
-  if (path.length() > PATH_MAX)
+  if (path.length() >= PATH_MAX)
     return false;
 
   *full_path = path;
diff --git a/debugd/src/helper_utils_test.cc b/debugd/src/helper_utils_test.cc
index c4eb2b7..490af5e 100644
--- a/debugd/src/helper_utils_test.cc
+++ b/debugd/src/helper_utils_test.cc
@@ -4,6 +4,8 @@
 
 #include "debugd/src/helper_utils.h"
 
+#include <limits.h>
+
 #include <gtest/gtest.h>
 
 namespace debugd {
@@ -16,6 +18,9 @@
 
   EXPECT_TRUE(GetHelperPath("test/me", &full_path));
   EXPECT_EQ("/usr/libexec/debugd/helpers/test/me", full_path);
+
+  std::string str(PATH_MAX, 'x');
+  EXPECT_FALSE(GetHelperPath(str, &full_path));
 }
 
 }  // namespace debugd