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: sandbox/linux/suid/common/suid_unsafe_environment_variables.h

Issue 236083002: Linux sandbox: style cleanup for setuid sandbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Also fix header inclusions. Ohh goodness. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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 // This is a list of environment variables which the ELF loader unsets when 5 // This is a list of environment variables which the ELF loader unsets when
6 // loading a SUID binary. Because they are unset rather than just ignored, they 6 // loading a SUID binary. Because they are unset rather than just ignored, they
7 // aren't passed to child processes of SUID processes either. 7 // aren't passed to child processes of SUID processes either.
8 // 8 //
9 // We need to save these environment variables before running a SUID sandbox 9 // We need to save these environment variables before running a SUID sandbox
10 // and restore them before running child processes (but after dropping root). 10 // and restore them before running child processes (but after dropping root).
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 "TZDIR", 47 "TZDIR",
48 NULL, 48 NULL,
49 }; 49 };
50 50
51 // Return a malloc allocated string containing the 'saved' environment variable 51 // Return a malloc allocated string containing the 'saved' environment variable
52 // name for a given environment variable. 52 // name for a given environment variable.
53 static inline char* SandboxSavedEnvironmentVariable(const char* envvar) { 53 static inline char* SandboxSavedEnvironmentVariable(const char* envvar) {
54 const size_t envvar_len = strlen(envvar); 54 const size_t envvar_len = strlen(envvar);
55 const size_t kMaxSizeT = (size_t) -1; 55 const size_t kMaxSizeT = (size_t) -1;
56 56
57 if (envvar_len > kMaxSizeT - 1 -8) 57 if (envvar_len > kMaxSizeT - 1 - 8)
58 return NULL; 58 return NULL;
59 59
60 const size_t saved_envvarlen = envvar_len + 1 /* NUL terminator */ + 60 const size_t saved_envvarlen = envvar_len + 1 /* NUL terminator */ +
61 8 /* strlen("SANDBOX_") */; 61 8 /* strlen("SANDBOX_") */;
62 char* const saved_envvar = (char*) malloc(saved_envvarlen); 62 char* const saved_envvar = (char*) malloc(saved_envvarlen);
63 if (!saved_envvar) 63 if (!saved_envvar)
64 return NULL; 64 return NULL;
65 65
66 memcpy(saved_envvar, "SANDBOX_", 8); 66 memcpy(saved_envvar, "SANDBOX_", 8);
67 memcpy(saved_envvar + 8, envvar, envvar_len); 67 memcpy(saved_envvar + 8, envvar, envvar_len);
68 saved_envvar[8 + envvar_len] = 0; 68 saved_envvar[8 + envvar_len] = 0;
69 69
70 return saved_envvar; 70 return saved_envvar;
71 } 71 }
72 72
73 #endif // SANDBOX_LINUX_SUID_SUID_UNSAFE_ENVIRONMENT_VARIABLES_H_ 73 #endif // SANDBOX_LINUX_SUID_SUID_UNSAFE_ENVIRONMENT_VARIABLES_H_
OLDNEW
« no previous file with comments | « sandbox/linux/suid/client/setuid_sandbox_client_unittest.cc ('k') | sandbox/linux/suid/linux_util.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698