OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The following is duplicated from base/linux_utils.cc. | 5 // The following is duplicated from base/linux_utils.cc. |
6 // We shouldn't link against C++ code in a setuid binary. | 6 // We shouldn't link against C++ code in a setuid binary. |
7 | 7 |
8 #include "linux_util.h" | 8 #include "linux_util.h" |
9 | 9 |
10 #include <dirent.h> | 10 #include <dirent.h> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 continue; | 76 continue; |
77 } | 77 } |
78 | 78 |
79 char buf[256]; | 79 char buf[256]; |
80 snprintf(buf, sizeof(buf), "/proc/%lu/fd", pid_ul); | 80 snprintf(buf, sizeof(buf), "/proc/%lu/fd", pid_ul); |
81 DIR* fd = opendir(buf); | 81 DIR* fd = opendir(buf); |
82 if (!fd) | 82 if (!fd) |
83 continue; | 83 continue; |
84 | 84 |
85 while ((dent = readdir(fd))) { | 85 while ((dent = readdir(fd))) { |
86 if (snprintf(buf, sizeof(buf), "/proc/%lu/fd/%s", pid_ul, | 86 int printed = snprintf(buf, sizeof(buf), "/proc/%lu/fd/%s", pid_ul, |
87 dent->d_name) >= sizeof(buf) - 1) { | 87 dent->d_name); |
| 88 if (printed < 0 || printed >= (int)(sizeof(buf) - 1)) { |
88 continue; | 89 continue; |
89 } | 90 } |
90 | 91 |
91 ino_t fd_inode; | 92 ino_t fd_inode; |
92 if (ProcPathGetInode(&fd_inode, buf)) { | 93 if (ProcPathGetInode(&fd_inode, buf)) { |
93 if (fd_inode == socket_inode) { | 94 if (fd_inode == socket_inode) { |
94 if (already_found) { | 95 if (already_found) { |
95 closedir(fd); | 96 closedir(fd); |
96 closedir(proc); | 97 closedir(proc); |
97 return false; | 98 return false; |
98 } | 99 } |
99 | 100 |
100 already_found = true; | 101 already_found = true; |
101 *pid_out = pid_ul; | 102 *pid_out = pid_ul; |
102 break; | 103 break; |
103 } | 104 } |
104 } | 105 } |
105 } | 106 } |
106 closedir(fd); | 107 closedir(fd); |
107 } | 108 } |
108 closedir(proc); | 109 closedir(proc); |
109 | 110 |
110 return already_found; | 111 return already_found; |
111 } | 112 } |
OLD | NEW |