Bug 1391494 - Enforce use of our own copy of strlcpy.
MozReview-Commit-ID: GQgGJBj1Hjc
--- 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);
}
}