Index: base/base_paths_linux.cc |
diff --git a/base/base_paths_linux.cc b/base/base_paths_linux.cc |
index b082eb3b3d71e6811ed385541df2df7268d1bb0e..d1b56430f2ea42211bbb2bb7eb9700858c109de4 100644 |
--- a/base/base_paths_linux.cc |
+++ b/base/base_paths_linux.cc |
@@ -50,13 +50,14 @@ bool PathProviderPosix(int key, FilePath* result) { |
int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
char bin_dir[PATH_MAX + 1]; |
size_t length = sizeof(bin_dir); |
+ // Upon return, |length| is the number of bytes written to |bin_dir| |
+ // including the string terminator. |
int error = sysctl(name, 4, bin_dir, &length, NULL, 0); |
- if (error < 0 || length == 0 || strlen(bin_dir) == 0) { |
+ if (error < 0 || length <= 1) { |
NOTREACHED() << "Unable to resolve path."; |
return false; |
} |
- bin_dir[strlen(bin_dir)] = 0; |
- *result = FilePath(bin_dir); |
+ *result = FilePath(FilePath::StringType(bin_dir, length - 1)); |
return true; |
#elif defined(OS_SOLARIS) |
char bin_dir[PATH_MAX + 1]; |