Bug 1391494 - Enforce use of our own copy of strlcpy. draft
authorGian-Carlo Pascutto <gcp@mozilla.com>
Thu, 24 Aug 2017 19:12:14 +0200
changeset 652248 e973433b763b51aea6c7fb098fe5e15e14351826
parent 652247 2510955b5c905a325b64384ba9c77bea407a4735
child 728044 11e5a63de686fd4bc790f8493c90e24ff1cea37f
push id76009
push usergpascutto@mozilla.com
push dateThu, 24 Aug 2017 17:12:44 +0000
bugs1391494
milestone57.0a1
Bug 1391494 - Enforce use of our own copy of strlcpy. MozReview-Commit-ID: GQgGJBj1Hjc
security/sandbox/linux/broker/SandboxBrokerRealpath.cpp
--- a/security/sandbox/linux/broker/SandboxBrokerRealpath.cpp
+++ b/security/sandbox/linux/broker/SandboxBrokerRealpath.cpp
@@ -41,31 +41,28 @@ static char sccsid[] = "@(#)realpath.c	8
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
 #include "base/string_util.h"
 #include "SandboxBroker.h"
 
-// base::strlcpy
-using namespace base;
-
 // Original copy in, but not usable from here:
 // toolkit/crashreporter/google-breakpad/src/common/linux/linux_libc_support.cc
 static size_t my_strlcat(char* s1, const char* s2, size_t len) {
   size_t pos1 = 0;
 
   while (pos1 < len && s1[pos1] != '\0')
     pos1++;
 
   if (pos1 == len)
     return pos1;
 
-  return pos1 + strlcpy(s1 + pos1, s2, len - pos1);
+  return pos1 + base::strlcpy(s1 + pos1, s2, len - pos1);
 }
 
 namespace mozilla {
 
 /*
  * Original: realpath
  * Find the real name of path, by removing all ".", ".." and symlink
  * components.  Returns (resolved) on success, or (NULL) on failure,
@@ -107,29 +104,29 @@ char* SandboxBroker::SymlinkPath(const P
     symlinks = 0;
     backup_allowed = PATH_MAX;
     if (path[0] == '/') {
         resolved[0] = '/';
         resolved[1] = '\0';
         if (path[1] == '\0')
             return (resolved);
         resolved_len = 1;
-        left_len = strlcpy(left, path + 1, sizeof(left));
+        left_len = base::strlcpy(left, path + 1, sizeof(left));
     } else {
         if (getcwd(resolved, PATH_MAX) == NULL) {
             if (m)
                 free(resolved);
             else {
                 resolved[0] = '.';
                 resolved[1] = '\0';
             }
             return (NULL);
         }
         resolved_len = strlen(resolved);
-        left_len = strlcpy(left, path, sizeof(left));
+        left_len = base::strlcpy(left, path, sizeof(left));
     }
     if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) {
         if (m)
             free(resolved);
         errno = ENAMETOOLONG;
         return (NULL);
     }
 
@@ -269,17 +266,17 @@ char* SandboxBroker::SymlinkPath(const P
                 left_len = my_strlcat(symlink, left, sizeof(symlink));
                 if (left_len >= sizeof(left)) {
                     if (m)
                         free(resolved);
                     errno = ENAMETOOLONG;
                     return (NULL);
                 }
             }
-            left_len = strlcpy(left, symlink, sizeof(left));
+            left_len = base::strlcpy(left, symlink, sizeof(left));
             backup_allowed = 0;
         } else if (!S_ISDIR(sb.st_mode) && p != NULL) {
             if (m)
                 free(resolved);
             errno = ENOTDIR;
             return (NULL);
         }
     }