Hello tech@,
I took a quick glance at ksh and one of the first things I noticed was
that it uses some sanatizing code on argv. When looking at execve(2) I
see that EINVAL or EFAULT are returned when argv isn't properly
formatted. I've also verified this quickly by a small PoC and in
sys/kern/kern_exec.c.
Would it make sense to remove the check all together?
Furthermore I see that kshname is based on directly dereferencing argv.
Although it's semantics I personally reckon it's cleaner to do it by
array index.
Sincerely,
Martijn van Duren
Index: main.c
===================================================================
RCS file: /cvs/src/bin/ksh/main.c,v
retrieving revision 1.55
diff -u -p -r1.55 main.c
--- main.c 9 Feb 2015 09:09:30 -0000 1.55
+++ main.c 31 Aug 2015 19:51:25 -0000
@@ -100,16 +100,7 @@ main(int argc, char *argv[])
struct env env;
pid_t ppid;
- /* make sure argv[] is sane */
- if (!*argv) {
- static const char *empty_argv[] = {
- "ksh", (char *) 0
- };
-
- argv = (char **) empty_argv;
- argc = 1;
- }
- kshname = *argv;
+ kshname = argv[0];
ainit(&aperm); /* initialize permanent Area */