mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Improve execve() path argument munging
Munging of paths passed inside the system() interpreter command is no longer supported. You have to pass your paths to posix_spawn() or the execve() family of functions if you want them to be munged. The first three characters must match `^/[a-z]/` in which case, it'll be turned into a DOS-style drive path with backslashes.
This commit is contained in:
parent
529cb4817c
commit
32b97f2d25
5 changed files with 88 additions and 78 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/intrin/getenv.internal.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#include "libc/proc/ntspawn.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -51,38 +52,6 @@ static textwindows int Compare(const char *l, const char *r) {
|
|||
return a - b;
|
||||
}
|
||||
|
||||
static textwindows void FixPath(char *path) {
|
||||
char *p;
|
||||
|
||||
// turn colon into semicolon
|
||||
// unless it already looks like a dos path
|
||||
for (p = path; *p; ++p) {
|
||||
if (p[0] == ':' && p[1] != '\\') {
|
||||
p[0] = ';';
|
||||
}
|
||||
}
|
||||
|
||||
// turn /c/... into c:\...
|
||||
p = path;
|
||||
if (p[0] == '/' && IsAlpha(p[1]) && p[2] == '/') {
|
||||
p[0] = p[1];
|
||||
p[1] = ':';
|
||||
}
|
||||
for (; *p; ++p) {
|
||||
if (p[0] == ';' && p[1] == '/' && IsAlpha(p[2]) && p[3] == '/') {
|
||||
p[1] = p[2];
|
||||
p[2] = ':';
|
||||
}
|
||||
}
|
||||
|
||||
// turn slash into backslash
|
||||
for (p = path; *p; ++p) {
|
||||
if (*p == '/') {
|
||||
*p = '\\';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static textwindows int InsertString(struct EnvBuilder *env, const char *str) {
|
||||
int c, i, cmp;
|
||||
char *var, *path = 0;
|
||||
|
@ -101,7 +70,7 @@ static textwindows int InsertString(struct EnvBuilder *env, const char *str) {
|
|||
} while (c);
|
||||
|
||||
// fixup key=/c/... → key=c:\...
|
||||
if (path) FixPath(path);
|
||||
if (path) mungentpath(path);
|
||||
|
||||
// append key=val to sorted list using insertion sort technique
|
||||
for (i = env->vari;; --i) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue