Skip to content

Commit 985e8e7

Browse files
0-v-0thewilsonator
authored andcommitted
Fix #18567 - quote spaced linker argv0 paths
1 parent b2c40a5 commit 985e8e7

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

compiler/src/dmd/link.d

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ version (Windows)
179179
assert(test(`"/LIBPATH:dir with spaces"`) == `"/LIBPATH:dir with spaces"`);
180180
assert(test(`/LIBPATH:"dir with spaces"`) == `/LIBPATH:"dir with spaces"`);
181181
}
182+
183+
private const(char)* quotedArgIfNeeded(ref OutBuffer buffer, const(char)* arg)
184+
{
185+
buffer.reset();
186+
buffer.writeQuotedArgIfNeeded(arg);
187+
return buffer.peekChars();
188+
}
182189
}
183190

184191
enum STATUS_FAILED = -1;
@@ -809,7 +816,8 @@ version (Windows)
809816
status = executearg0(cmd, args);
810817
if (status == -1)
811818
{
812-
status = spawnlp(0, cmd, cmd, args, null);
819+
OutBuffer quotedCmd;
820+
status = spawnlp(0, cmd, quotedArgIfNeeded(quotedCmd, cmd), args, null);
813821
}
814822
}
815823
if (status)
@@ -844,8 +852,9 @@ version (Windows)
844852
return -1;
845853
const file = FileName.replaceName(argv0, cmd.toDString);
846854
//printf("spawning '%s'\n",file);
855+
OutBuffer quotedFile;
847856
// spawnlp returns intptr_t in some systems, not int
848-
return spawnl(0, file.ptr, file.ptr, args, null);
857+
return spawnl(0, file.ptr, quotedArgIfNeeded(quotedFile, file.ptr), args, null);
849858
}
850859
}
851860

0 commit comments

Comments
 (0)