Skip to content

Commit c97414b

Browse files
author
git-core
committed
Revert "Inherit the environment of the caller process for a new process image"
This reverts commit e0329ce.
1 parent b7744e9 commit c97414b

File tree

2 files changed

+1
-37
lines changed

2 files changed

+1
-37
lines changed

su.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ static int from_init(struct su_initiator *from)
5959
ssize_t len;
6060
int i;
6161
int err;
62-
size_t j;
6362

6463
from->uid = getuid();
6564
from->pid = getppid();
@@ -114,31 +113,6 @@ static int from_init(struct su_initiator *from)
114113
strncpy(from->bin, argv0, sizeof(from->bin));
115114
from->bin[sizeof(from->bin)-1] = '\0';
116115

117-
/* Get the environment of the calling process */
118-
snprintf(path, sizeof(path), "/proc/%u/environ", from->pid);
119-
fd = open(path, O_RDONLY);
120-
if (fd < 0) {
121-
PLOGE("Opening environment");
122-
goto out;
123-
}
124-
len = read(fd, from->env, sizeof(from->env));
125-
err = errno;
126-
close(fd);
127-
if (len < 0 || len == sizeof(from->env)) {
128-
PLOGEV("Reading environment", err);
129-
goto out;
130-
}
131-
from->env[len] = '\0';
132-
133-
from->envp[0] = &from->env[0];
134-
for (i = 0, j = 0; i < len && j < ARRAY_SIZE(from->envp); i++) {
135-
if (from->env[i] == '\0') {
136-
from->envp[++j] = &from->env[i + 1];
137-
}
138-
}
139-
from->envp[j] = NULL;
140-
141-
out:
142116
return 0;
143117
}
144118

@@ -307,7 +281,6 @@ static void deny(const struct su_context *ctx)
307281
static void allow(const struct su_context *ctx)
308282
{
309283
char *arg0;
310-
char * const* envp = environ;
311284
int argc, err;
312285

313286
umask(ctx->umask);
@@ -326,9 +299,6 @@ static void allow(const struct su_context *ctx)
326299
strcpy(p + 1, arg0);
327300
arg0 = p;
328301
}
329-
if (ctx->from.envp[0]) {
330-
envp = ctx->from.envp;
331-
}
332302
if (setresgid(ctx->to.uid, ctx->to.uid, ctx->to.uid)) {
333303
PLOGE("setresgid (%u)", ctx->to.uid);
334304
exit(EXIT_FAILURE);
@@ -354,7 +324,7 @@ static void allow(const struct su_context *ctx)
354324
ctx->to.argv[--argc] = "-c";
355325
}
356326
ctx->to.argv[--argc] = arg0;
357-
execve(ctx->to.shell, ctx->to.argv + argc, envp);
327+
execv(ctx->to.shell, ctx->to.argv + argc);
358328
err = errno;
359329
PLOGE("exec");
360330
fprintf(stderr, "Cannot execute %s: %s\n", ctx->to.shell, strerror(err));
@@ -369,8 +339,6 @@ int main(int argc, char *argv[])
369339
.uid = 0,
370340
.bin = "",
371341
.args = "",
372-
.env = "",
373-
.envp = { NULL },
374342
},
375343
.to = {
376344
.uid = AID_ROOT,

su.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ struct su_initiator {
5353
unsigned uid;
5454
char bin[PATH_MAX];
5555
char args[4096];
56-
char env[ARG_MAX];
57-
char *envp[512];
5856
};
5957

6058
struct su_request {
@@ -102,6 +100,4 @@ static inline char *get_command(const struct su_request *to)
102100
#define PLOGE(fmt,args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
103101
#define PLOGEV(fmt,err,args...) LOGE(fmt " failed with %d: %s", ##args, err, strerror(err))
104102

105-
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
106-
107103
#endif

0 commit comments

Comments
 (0)