Skip to content

Commit 8ca0e94

Browse files
committed
process: Increase maximum argument size and report when running out of it.
1 parent ab818b2 commit 8ca0e94

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

src/watt/process/sink.volt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,38 @@ import io = watt.io;
99
struct CStrSink
1010
{
1111
public:
12-
strStorage: char[16*1024];
12+
strStorage: char[256*1024];
1313
ptrStorage: char*[4*1024];
1414
strLoc: size_t;
1515
ptrLoc: size_t;
1616

1717

1818
public:
19-
fn addArgz(str: SinkArg)
19+
fn addArgz(str: SinkArg) bool
2020
{
2121
len := str.length + 1;
2222
if (!checkStorage(len)) {
23-
return;
23+
return false;
2424
}
2525

2626
ptrStorage[ptrLoc++] = &strStorage.ptr[strLoc];
2727
add(str, '\0');
28+
29+
return true;
2830
}
2931

30-
fn addEnvz(key: SinkArg, value: SinkArg)
32+
fn addEnvz(key: SinkArg, value: SinkArg) bool
3133
{
3234
len := key.length + 1 + value.length + 1;
3335
if (!checkStorage(len)) {
34-
return;
36+
return false;
3537
}
3638

3739
ptrStorage[ptrLoc++] = &strStorage.ptr[strLoc];
3840
add(key, '=');
3941
add(value, '\0');
42+
43+
return true;
4044
}
4145

4246

src/watt/process/spawn.volt

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,14 @@ version (Posix) {
270270
argz: CStrSink;
271271
envz: CStrSink;
272272

273-
if (env !is null) {
274-
// Fill out the envz to be given to execve.
275-
foreach (k, v; env.store) {
276-
envz.addEnvz(k, v);
277-
}
273+
// Fill out the envz to be given to execve, null safe.
274+
if (!envz.toEnvz(env)) {
275+
throw new ProcessException("Environment to large");
278276
}
279277

280278
// Setup the argz to be given to execv[e].
281-
argz.addArgz(name);
282-
foreach (arg; args) {
283-
argz.addArgz(arg);
279+
if (!argz.toArgz(name, args)) {
280+
throw new ProcessException("Out of argument memory");
284281
}
285282

286283
pid := fork();
@@ -366,6 +363,37 @@ version (Posix) {
366363
}
367364
}
368365

366+
private fn toArgz(ref argz: CStrSink, name: string, args: string[]) bool
367+
{
368+
if (!argz.addArgz(name)) {
369+
return false;
370+
}
371+
372+
foreach (arg; args) {
373+
if (!argz.addArgz(arg)) {
374+
return false;
375+
}
376+
}
377+
378+
return true;
379+
}
380+
381+
private fn toEnvz(ref envz: CStrSink, env: Environment) bool
382+
{
383+
if (env is null) {
384+
return true;
385+
}
386+
387+
// Fill out the envz to be given to execve.
388+
foreach (k, v; env.store) {
389+
if (!envz.addEnvz(k, v)) {
390+
return false;
391+
}
392+
}
393+
394+
return true;
395+
}
396+
369397
private fn stopped(status: i32) bool { return (status & 0xff) == 0x7f; }
370398
private fn signaled(status: i32) bool { return ((((status & 0x7f) + 1) & 0xff) >> 1) > 0; }
371399
private fn exited(status: i32) bool { return (status & 0x7f) == 0; }
@@ -374,6 +402,7 @@ version (Posix) {
374402
private fn exitstatus(status: i32) i32 { return (status & 0xff00) >> 8; }
375403

376404
} else version (Windows) {
405+
377406
private fn toArgz(moduleName: string, args: string[]) LPSTR
378407
{
379408
buffer: StringSink;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy