summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-12-21 17:12:42 +0000
committermidipix <writeonce@midipix.org>2017-12-22 05:18:57 -0500
commit15812f04c290bf84865678fd04e6beacc93fb6a6 (patch)
treeb4c081be7c72a78db6b3e87d1cb1a09324441d85
parent2104cf1edacf8b53caeebc2337404a4b0b46e557 (diff)
downloadntapi-15812f04c290bf84865678fd04e6beacc93fb6a6.tar.bz2
ntapi-15812f04c290bf84865678fd04e6beacc93fb6a6.tar.xz
tt_array_copy_utf8(): properly implement the interp-optarg-script semantics.
-rw-r--r--include/ntapi/nt_argv.h6
-rw-r--r--src/argv/ntapi_tt_array_utf8.c75
-rw-r--r--src/process/ntapi_tt_spawn_native_process.c2
3 files changed, 57 insertions, 26 deletions
diff --git a/include/ntapi/nt_argv.h b/include/ntapi/nt_argv.h
index de149dc..a75d538 100644
--- a/include/ntapi/nt_argv.h
+++ b/include/ntapi/nt_argv.h
@@ -157,10 +157,10 @@ typedef int32_t __stdcall ntapi_tt_get_env_var_meta_utf16(
typedef int32_t __stdcall ntapi_tt_array_copy_utf8(
__out int * argc,
__in const char ** argv,
- __in const char ** wenvp,
- __in const char * image_name __optional,
- __in const char * interpreter __optional,
+ __in const char ** envp,
+ __in const char * interp __optional,
__in const char * optarg __optional,
+ __in const char * script __optional,
__in void * base,
__out void * buffer,
__in size_t buflen,
diff --git a/src/argv/ntapi_tt_array_utf8.c b/src/argv/ntapi_tt_array_utf8.c
index 6c061f4..27c6729 100644
--- a/src/argv/ntapi_tt_array_utf8.c
+++ b/src/argv/ntapi_tt_array_utf8.c
@@ -14,9 +14,9 @@ int32_t __stdcall __ntapi_tt_array_copy_utf8(
__out int * argc,
__in const char ** argv,
__in const char ** envp,
- __in const char * image_name __optional,
- __in const char * interpreter __optional,
- __in const char * optarg __optional,
+ __in const char * interp,
+ __in const char * optarg,
+ __in const char * script,
__in void * base,
__out void * buffer,
__in size_t buflen,
@@ -24,40 +24,55 @@ int32_t __stdcall __ntapi_tt_array_copy_utf8(
{
const char ** parg;
const char * arg;
- const char * dummy;
+ const char * mark;
char * ch;
ptrdiff_t diff;
ptrdiff_t ptrs;
size_t needed;
-
- /* unused params */
- (void)interpreter;
- (void)optarg;
+ const char * dummy[2] = {0,0};
/* fallback */
- dummy = 0;
- argv = argv ? argv : &dummy;
- envp = envp ? envp : &dummy;
+ argv = argv ? argv : dummy;
+ envp = envp ? envp : dummy;
/* ptrs, needed */
ptrs = 0;
needed = 0;
- if (image_name) {
+ /* interpr */
+ if (interp) {
+ ptrs++;
+ needed += sizeof(char *)
+ + __ntapi->tt_string_null_offset_multibyte(interp)
+ + sizeof(char);
+ }
+
+ /* optarg */
+ if (optarg) {
ptrs++;
needed += sizeof(char *)
- + __ntapi->tt_string_null_offset_multibyte(image_name)
+ + __ntapi->tt_string_null_offset_multibyte(optarg)
+ sizeof(char);
}
- for (parg=argv; *parg; parg++)
+ /* script / argv[0] */
+ if ((mark = script ? script : argv[0])) {
+ ptrs++;
+ needed += sizeof(char *)
+ + __ntapi->tt_string_null_offset_multibyte(mark)
+ + sizeof(char);
+ }
+
+ /* argv */
+ for (parg=&argv[1]; *parg; parg++)
needed += sizeof(char *)
+ __ntapi->tt_string_null_offset_multibyte(*parg)
+ sizeof(char);
- ptrs += (parg - argv);
+ ptrs += (parg - &argv[1]);
*argc = (int)ptrs;
+ /* envp */
for (parg=envp; *parg; parg++)
needed += sizeof(char *)
+ __ntapi->tt_string_null_offset_multibyte(*parg)
@@ -65,8 +80,8 @@ int32_t __stdcall __ntapi_tt_array_copy_utf8(
ptrs += (parg - envp);
- ptrs += 2;
- needed += 2*sizeof(char *);
+ ptrs += 2;
+ needed += 2*sizeof(char *);
blklen = blklen ? blklen : &needed;
*blklen = needed;
@@ -75,19 +90,35 @@ int32_t __stdcall __ntapi_tt_array_copy_utf8(
/* init */
parg = (const char **)buffer;
- ch = (char *)(parg+ptrs);
+ ch = (char *)(parg+ptrs);
diff = (ptrdiff_t)base;
- /* image_name */
- if (image_name) {
+ /* interp */
+ if (interp) {
+ *parg++ = ch-diff;
+ for (arg=interp; *arg; arg++,ch++)
+ *ch = *arg;
+ *ch++ = '\0';
+ }
+
+ /* optarg */
+ if (optarg) {
+ *parg++ = ch-diff;
+ for (arg=optarg; *arg; arg++,ch++)
+ *ch = *arg;
+ *ch++ = '\0';
+ }
+
+ /* script / argv[0] */
+ if ((mark = script ? script : argv[0])) {
*parg++ = ch-diff;
- for (arg=image_name; *arg; arg++,ch++)
+ for (arg=mark; *arg; arg++,ch++)
*ch = *arg;
*ch++ = '\0';
}
/* argv */
- for (; *argv; argv++) {
+ for (++argv; *argv; argv++) {
*parg++=ch-diff;
for (arg=*argv; *arg; arg++,ch++)
*ch = *arg;
diff --git a/src/process/ntapi_tt_spawn_native_process.c b/src/process/ntapi_tt_spawn_native_process.c
index a1712bb..580e645 100644
--- a/src/process/ntapi_tt_spawn_native_process.c
+++ b/src/process/ntapi_tt_spawn_native_process.c
@@ -165,9 +165,9 @@ int32_t __stdcall __ntapi_tt_spawn_native_process(nt_spawn_process_params * spar
&rdata->argc,
(const char **)sparams->argv,
(const char **)sparams->envp,
- sparams->script,
sparams->interp,
sparams->optarg,
+ sparams->script,
rtblock.addr,
rdata->buffer,
buflen,&written)))