Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/zygote_main_linux.cc

Issue 159216: Linux: add support for tm_zone to localtime via the sandbox. (Closed)
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <unistd.h> 5 #include <unistd.h>
6 #include <sys/epoll.h> 6 #include <sys/epoll.h>
7 #include <sys/types.h> 7 #include <sys/types.h>
8 #include <sys/socket.h> 8 #include <sys/socket.h>
9 #include <sys/signal.h> 9 #include <sys/signal.h>
10 #include <sys/prctl.h> 10 #include <sys/prctl.h>
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 for (std::vector<int>::const_iterator 196 for (std::vector<int>::const_iterator
197 i = fds.begin(); i != fds.end(); ++i) 197 i = fds.begin(); i != fds.end(); ++i)
198 close(*i); 198 close(*i);
199 return false; 199 return false;
200 } 200 }
201 }; 201 };
202 202
203 // Patched dynamic symbol wrapper functions... 203 // Patched dynamic symbol wrapper functions...
204 namespace sandbox_wrapper { 204 namespace sandbox_wrapper {
205 205
206 void do_localtime(time_t input, struct tm* output) { 206 void do_localtime(time_t input, struct tm* output, char* timezone_out,
207 size_t timezone_out_len) {
207 Pickle request; 208 Pickle request;
208 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME); 209 request.WriteInt(LinuxSandbox::METHOD_LOCALTIME);
209 request.WriteString( 210 request.WriteString(
210 std::string(reinterpret_cast<char*>(&input), sizeof(input))); 211 std::string(reinterpret_cast<char*>(&input), sizeof(input)));
211 212
212 uint8_t reply_buf[512]; 213 uint8_t reply_buf[512];
213 const ssize_t r = base::SendRecvMsg( 214 const ssize_t r = base::SendRecvMsg(
214 kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL, request); 215 kMagicSandboxIPCDescriptor, reply_buf, sizeof(reply_buf), NULL, request);
215 if (r == -1) { 216 if (r == -1) {
216 memset(output, 0, sizeof(struct tm)); 217 memset(output, 0, sizeof(struct tm));
217 return; 218 return;
218 } 219 }
219 220
220 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 221 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
221 void* iter = NULL; 222 void* iter = NULL;
222 std::string result; 223 std::string result, timezone;
223 if (!reply.ReadString(&iter, &result) || 224 if (!reply.ReadString(&iter, &result) ||
225 !reply.ReadString(&iter, &timezone) ||
224 result.size() != sizeof(struct tm)) { 226 result.size() != sizeof(struct tm)) {
225 memset(output, 0, sizeof(struct tm)); 227 memset(output, 0, sizeof(struct tm));
226 return; 228 return;
227 } 229 }
228 230
229 memcpy(output, result.data(), sizeof(struct tm)); 231 memcpy(output, result.data(), sizeof(struct tm));
232 if (timezone_out_len) {
233 const size_t copy_len = std::min(timezone_out_len - 1, timezone.size());
234 memcpy(timezone_out, timezone.data(), copy_len);
235 timezone_out[copy_len] = 0;
236 output->tm_zone = timezone_out;
237 } else {
238 output->tm_zone = NULL;
239 }
230 } 240 }
231 241
232 struct tm* localtime(const time_t* timep) { 242 struct tm* localtime(const time_t* timep) {
233 static struct tm time_struct; 243 static struct tm time_struct;
234 do_localtime(*timep, &time_struct); 244 static char timezone_string[64];
245 do_localtime(*timep, &time_struct, timezone_string, sizeof(timezone_string));
235 return &time_struct; 246 return &time_struct;
236 } 247 }
237 248
238 struct tm* localtime_r(const time_t* timep, struct tm* result) { 249 struct tm* localtime_r(const time_t* timep, struct tm* result) {
239 do_localtime(*timep, result); 250 do_localtime(*timep, result, NULL, 0);
240 return result; 251 return result;
241 } 252 }
242 253
243 } // namespace sandbox_wrapper 254 } // namespace sandbox_wrapper
244 255
245 /* On IA-32, function calls which need to be resolved by the dynamic linker are 256 /* On IA-32, function calls which need to be resolved by the dynamic linker are
246 * directed to the producure linking table (PLT). Each PLT entry contains code 257 * directed to the producure linking table (PLT). Each PLT entry contains code
247 * which jumps (indirectly) via the global offset table (GOT): 258 * which jumps (indirectly) via the global offset table (GOT):
248 * Dump of assembler code for function f@plt: 259 * Dump of assembler code for function f@plt:
249 * 0x0804830c <f@plt+0>: jmp *0x804a004 # GOT indirect jump 260 * 0x0804830c <f@plt+0>: jmp *0x804a004 # GOT indirect jump
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 bool ZygoteMain(const MainFunctionParams& params) { 371 bool ZygoteMain(const MainFunctionParams& params) {
361 if (!MaybeEnterChroot()) { 372 if (!MaybeEnterChroot()) {
362 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " 373 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: "
363 << errno << ")"; 374 << errno << ")";
364 return false; 375 return false;
365 } 376 }
366 377
367 Zygote zygote; 378 Zygote zygote;
368 return zygote.ProcessRequests(); 379 return zygote.ProcessRequests();
369 } 380 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698