[PATCH 1/5] start.exe: unquote the title
Damjan Jovanovic
damjan.jov at gmail.com
Sat Aug 3 22:24:26 CDT 2019
Signed-off-by: Damjan Jovanovic <damjan.jov at gmail.com>
---
programs/start/resources.h | 1 +
programs/start/start.c | 28 +++++++++++++++++++++++++++-
programs/start/start.rc | 2 ++
3 files changed, 30 insertions(+), 1 deletion(-)
-------------- next part --------------
diff --git a/programs/start/resources.h b/programs/start/resources.h
index d965de620e..bbc05350f9 100644
--- a/programs/start/resources.h
+++ b/programs/start/resources.h
@@ -23,3 +23,4 @@
#define STRING_USAGE 101
#define STRING_EXECFAIL 103
#define STRING_UNIXFAIL 104
+#define STRING_NOMEMFORTITLE 105
diff --git a/programs/start/start.c b/programs/start/start.c
index 18fd5f517f..8e40d5156c 100644
--- a/programs/start/start.c
+++ b/programs/start/start.c
@@ -172,6 +172,25 @@ static BOOL is_option(const WCHAR* arg, const WCHAR* opt)
arg, -1, opt, -1) == CSTR_EQUAL;
}
+static void parse_title(const WCHAR *arg, WCHAR *title, int size)
+{
+ /* See:
+ * WCMD_start() in programs/cmd/builtins.c
+ * WCMD_parameter_with_delims() in programs/cmd/batch.c
+ * The shell has already tokenized the command line for us.
+ * All we need to do is filter out all the quotes.
+ */
+
+ int next;
+ const WCHAR *p = arg;
+
+ for (next = 0; next < (size-1) && *p; p++) {
+ if (*p != '"')
+ title[next++] = *p;
+ }
+ title[next] = '\0';
+}
+
int wmain (int argc, WCHAR *argv[])
{
SHELLEXECUTEINFOW sei;
@@ -223,7 +242,13 @@ int wmain (int argc, WCHAR *argv[])
for (i=1; i<argc; i++) {
/* parse first quoted argument as console title */
if (!title && argv[i][0] == '"') {
- title = argv[i];
+ /* it will remove at least 1 quote */
+ int maxChars = lstrlenW(argv[1]);
+ title = HeapAlloc(GetProcessHeap(), 0, maxChars*sizeof(WCHAR));
+ if (title)
+ parse_title(argv[i], title, maxChars);
+ else
+ fatal_string(STRING_NOMEMFORTITLE);
continue;
}
if (argv[i][0] != '/')
@@ -457,6 +482,7 @@ done:
HeapFree( GetProcessHeap(), 0, args );
HeapFree( GetProcessHeap(), 0, dos_filename );
HeapFree( GetProcessHeap(), 0, parent_directory );
+ HeapFree( GetProcessHeap(), 0, title );
if (sei.fMask & SEE_MASK_NOCLOSEPROCESS) {
DWORD exitcode;
diff --git a/programs/start/start.rc b/programs/start/start.rc
index ad3aaeea76..385cb55347 100644
--- a/programs/start/start.rc
+++ b/programs/start/start.rc
@@ -57,4 +57,6 @@ Options:\n\
STRING_EXECFAIL, "Application could not be started, or no application associated with the specified file.\nShellExecuteEx failed"
STRING_UNIXFAIL "Could not translate the specified Unix filename to a DOS filename."
+
+STRING_NOMEMFORTITLE "Parsing the title failed: out of memory"
}
More information about the wine-devel
mailing list