summaryrefslogtreecommitdiff
path: root/su
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-03-17 12:35:45 -0700
committerElliott Hughes <enh@google.com>2015-03-17 13:15:15 -0700
commit436af25d872fdb68cad5dc9f83d0c8e44fe23790 (patch)
tree6092fed14d7275074ce137a4883d72af40a14fc4 /su
parent79522851f014d82768d7d27d5676bdf98cbb595a (diff)
downloadextras-436af25d872fdb68cad5dc9f83d0c8e44fe23790.tar.gz
Fix su.
Manually NULL-terminate the arguments array instead of trying to use memset. This was accidentally working on LP64 but fails reliably on LP32. Change-Id: Ic2ecb8ed2019f260c720f27dbd018a55e7cfa569
Diffstat (limited to 'su')
-rw-r--r--su/su.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/su/su.c b/su/su.c
index 75d68506..9e3144de 100644
--- a/su/su.c
+++ b/su/su.c
@@ -120,15 +120,16 @@ int main(int argc, char** argv) {
// TODO: reset $PATH.
// Set up the arguments for exec.
- char* exec_args[argc]; // Having too much space is fine.
- memset(exec_args, 0, sizeof(exec_args));
+ char* exec_args[argc + 1]; // Having too much space is fine.
// Skip "su" and copy any other args. We already skipped the optional uid above.
++argv;
- for (size_t i = 0; argv[i] != NULL; ++i) {
- exec_args[i] = argv[i];
+ size_t i = 0;
+ for (; *argv != NULL; ++i) {
+ exec_args[i] = *argv++;
}
// Default to the standard shell.
- if (!exec_args[0]) exec_args[0] = "/system/bin/sh";
+ if (i == 0) exec_args[i++] = "/system/bin/sh";
+ exec_args[i] = NULL;
execvp(exec_args[0], exec_args);
error(1, errno, "failed to exec %s", exec_args[0]);