Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/common/child_process_sandbox_support_impl_linux.h" | 5 #include "content/common/child_process_sandbox_support_impl_linux.h" |
| 6 | 6 |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 request.WriteBool(bold); | 92 request.WriteBool(bold); |
| 93 request.WriteBool(italic); | 93 request.WriteBool(italic); |
| 94 request.WriteUInt32(charset); | 94 request.WriteUInt32(charset); |
| 95 uint8_t reply_buf[64]; | 95 uint8_t reply_buf[64]; |
| 96 int fd = -1; | 96 int fd = -1; |
| 97 UnixDomainSocket::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf), | 97 UnixDomainSocket::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf), |
| 98 &fd, request); | 98 &fd, request); |
| 99 return fd; | 99 return fd; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool GetFontTable(int fd, uint32_t table, uint8_t* output, | 102 bool GetFontTable(int fd, uint32_t table, size_t offset, |
|
palmer
2013/03/14 19:26:43
Perhaps this should be off_t, since it's a file of
bbudge
2013/03/15 22:25:34
Done.
| |
| 103 size_t* output_length) { | 103 uint8_t* output, size_t* output_length) { |
|
palmer
2013/03/14 19:26:43
Same here.
bbudge
2013/03/15 22:25:34
'output_length' is the size of the data, so always
| |
| 104 if (table == 0) { | 104 if (table == 0) { |
| 105 struct stat st; | 105 struct stat st; |
| 106 if (fstat(fd, &st) < 0) | 106 if (fstat(fd, &st) < 0) |
| 107 return false; | 107 return false; |
| 108 size_t length = st.st_size; | 108 size_t length = st.st_size; |
|
palmer
2013/03/14 19:26:43
st_size is an off_t, which is not necessarily the
bbudge
2013/03/15 22:25:34
Thanks for pointing that out. I'll use the safe nu
| |
| 109 if (offset > length) | |
| 110 return false; | |
| 111 length -= offset; | |
|
Chris Evans
2013/03/14 18:15:30
I don't understand this change. This could be beca
bbudge
2013/03/14 18:21:26
It's a little tricky but the output_length paramet
| |
| 109 if (!output) { | 112 if (!output) { |
| 110 *output_length = length; | 113 *output_length = length; |
| 111 return true; | 114 return true; |
| 112 } | 115 } |
| 113 if (*output_length < length) | 116 length = std::min(length, *output_length); |
|
bbudge
2013/03/14 18:21:26
This is where the caller's output_len can limit th
palmer
2013/03/14 19:26:43
Yes, please. :)
bbudge
2013/03/15 22:25:34
Done. I added comments to explain this and some ot
| |
| 114 return false; | |
| 115 *output_length = length; | 117 *output_length = length; |
| 116 ssize_t n = HANDLE_EINTR(pread(fd, output, length, 0)); | 118 ssize_t n = HANDLE_EINTR(pread(fd, output, length, offset)); |
|
palmer
2013/03/14 19:26:43
Yeah, note again that pread takes an off_t offset.
bbudge
2013/03/15 22:25:34
Done.
| |
| 117 if (n != static_cast<ssize_t>(length)) | 119 if (n != static_cast<ssize_t>(length)) |
| 118 return false; | 120 return false; |
| 119 return true; | 121 return true; |
| 120 } | 122 } |
| 121 | 123 |
| 122 unsigned num_tables; | 124 unsigned num_tables; |
| 123 uint8_t num_tables_buf[2]; | 125 uint8_t num_tables_buf[2]; |
| 124 | 126 |
| 125 ssize_t n = HANDLE_EINTR(pread(fd, &num_tables_buf, sizeof(num_tables_buf), | 127 ssize_t n = HANDLE_EINTR(pread(fd, &num_tables_buf, sizeof(num_tables_buf), |
| 126 4 /* skip the font type */)); | 128 4 /* skip the font type */)); |
| 127 if (n != sizeof(num_tables_buf)) | 129 if (n != sizeof(num_tables_buf)) |
| 128 return false; | 130 return false; |
| 129 | 131 |
| 130 num_tables = static_cast<unsigned>(num_tables_buf[0]) << 8 | | 132 num_tables = static_cast<unsigned>(num_tables_buf[0]) << 8 | |
|
palmer
2013/03/14 19:26:43
NIT: So we are expecting a 16-bit number. Why not
bbudge
2013/03/15 22:25:34
Done.
| |
| 131 num_tables_buf[1]; | 133 num_tables_buf[1]; |
| 132 | 134 |
| 133 // The size in bytes of an entry in the table directory. | 135 // The size in bytes of an entry in the table directory. |
| 134 static const unsigned kTableEntrySize = 16; | 136 static const unsigned kTableEntrySize = 16; |
| 135 scoped_array<uint8_t> table_entries( | 137 scoped_array<uint8_t> table_entries( |
| 136 new uint8_t[num_tables * kTableEntrySize]); | 138 new uint8_t[num_tables * kTableEntrySize]); |
| 137 n = HANDLE_EINTR(pread(fd, table_entries.get(), num_tables * kTableEntrySize, | 139 n = HANDLE_EINTR(pread(fd, table_entries.get(), num_tables * kTableEntrySize, |
| 138 12 /* skip the SFNT header */)); | 140 12 /* skip the SFNT header */)); |
| 139 if (n != static_cast<ssize_t>(num_tables * kTableEntrySize)) | 141 if (n != static_cast<ssize_t>(num_tables * kTableEntrySize)) |
| 140 return false; | 142 return false; |
| 141 | 143 |
| 142 size_t offset; | 144 size_t table_offset = 0; |
| 143 size_t length = 0; | 145 size_t length = 0; |
| 144 for (unsigned i = 0; i < num_tables; i++) { | 146 for (unsigned i = 0; i < num_tables; i++) { |
| 145 const uint8_t* entry = table_entries.get() + i * kTableEntrySize; | 147 const uint8_t* entry = table_entries.get() + i * kTableEntrySize; |
| 146 if (memcmp(entry, &table, sizeof(table)) == 0) { | 148 if (memcmp(entry, &table, sizeof(table)) == 0) { |
| 147 offset = static_cast<size_t>(entry[8]) << 24 | | 149 table_offset = static_cast<size_t>(entry[8]) << 24 | |
|
palmer
2013/03/14 19:26:43
Are there generic ReadUint32, et c. functions we c
bbudge
2013/03/15 22:25:34
There are the base::NetToHost functions. The file
| |
| 148 static_cast<size_t>(entry[9]) << 16 | | 150 static_cast<size_t>(entry[9]) << 16 | |
| 149 static_cast<size_t>(entry[10]) << 8 | | 151 static_cast<size_t>(entry[10]) << 8 | |
| 150 static_cast<size_t>(entry[11]); | 152 static_cast<size_t>(entry[11]); |
| 151 length = static_cast<size_t>(entry[12]) << 24 | | 153 length = static_cast<size_t>(entry[12]) << 24 | |
| 152 static_cast<size_t>(entry[13]) << 16 | | 154 static_cast<size_t>(entry[13]) << 16 | |
| 153 static_cast<size_t>(entry[14]) << 8 | | 155 static_cast<size_t>(entry[14]) << 8 | |
| 154 static_cast<size_t>(entry[15]); | 156 static_cast<size_t>(entry[15]); |
| 155 | 157 |
| 156 break; | 158 break; |
| 157 } | 159 } |
| 158 } | 160 } |
| 159 | 161 |
| 160 if (!length) | 162 if (!length || offset > length) |
| 161 return false; | 163 return false; |
| 164 length -= offset; | |
| 162 | 165 |
| 163 if (!output) { | 166 if (!output) { |
| 164 *output_length = length; | 167 *output_length = length; |
| 165 return true; | 168 return true; |
| 166 } | 169 } |
| 167 | 170 |
| 168 if (*output_length < length) | 171 length = std::min(length, *output_length); |
| 169 return false; | |
| 170 | |
| 171 *output_length = length; | 172 *output_length = length; |
| 172 n = HANDLE_EINTR(pread(fd, output, length, offset)); | 173 n = HANDLE_EINTR(pread(fd, output, length, table_offset + offset)); |
| 173 if (n != static_cast<ssize_t>(length)) | 174 if (n != static_cast<ssize_t>(length)) |
| 174 return false; | 175 return false; |
| 175 | 176 |
| 176 return true; | 177 return true; |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace content | 180 } // namespace content |
| OLD | NEW |