summaryrefslogtreecommitdiff
path: root/src/user/app/testelf
diff options
context:
space:
mode:
authordzwdz2022-08-26 23:50:53 +0200
committerdzwdz2022-08-27 10:18:11 +0200
commit48e612a8c19ae1fd6aa1ab8fb48b03a0291110b4 (patch)
tree8c8d3da6c38206503364693b545aa6228a8c1f5a /src/user/app/testelf
parent35cbc783713c814298987ee636d26cfccc5aca96 (diff)
user/elfload: fix argv corruption when it's passed from the stack
Diffstat (limited to 'src/user/app/testelf')
-rw-r--r--src/user/app/testelf/main.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/user/app/testelf/main.c b/src/user/app/testelf/main.c
index ee7465b..ea97b4a 100644
--- a/src/user/app/testelf/main.c
+++ b/src/user/app/testelf/main.c
@@ -1,4 +1,6 @@
#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
const char *str = "Hello!", *str2 = "World.";
@@ -8,5 +10,16 @@ int main(int argc, char **argv) {
printf("argc == %u\n", argc);
for (int i = 0; i < argc; i++)
printf("argv[%u] == 0x%x == \"%s\"\n", i, argv[i], argv[i]);
+ if (strcmp(argv[1], "stackexec") == 0) {
+ /* exec something with arguments on the stack */
+ const char s_d[] = "I am a pretty long string on the stack. Oh my. " \
+ "I hope I won't get corrupted.\0";
+ char s[sizeof(s_d)];
+ memcpy(s, s_d, sizeof(s_d));
+ const char *argv2[] = {argv[0], s, s, "hello", s, s, s, "lol", NULL};
+ printf("argv2 == 0x%x, s == 0x%x\n== exec ==\n", argv2, s);
+ execv(argv[0], (void*)argv2);
+ puts("stackexec failed");
+ }
return 0;
}