diff options
author | Elliott Hughes <enh@google.com> | 2015-03-17 12:35:45 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-03-17 13:15:15 -0700 |
commit | 436af25d872fdb68cad5dc9f83d0c8e44fe23790 (patch) | |
tree | 6092fed14d7275074ce137a4883d72af40a14fc4 /su | |
parent | 79522851f014d82768d7d27d5676bdf98cbb595a (diff) | |
download | extras-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.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -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]); |