|
Re: Rshd - blanks in path names: msg#00006gnu.cegcc.devel
Danny Backx wrote: Pedro, Thanks for looking into it! That's a bit weird quoting, isn't it? If we go the escaping with '\\' route, 1) It would escape this: '\\path\\to\\prog\\ name.exe args' into this: '\path\to\prog\ name.exe' + 'args' while it should be: '\path\to\prog\ ' + 'name.exe args' (yep, a file named ' '). It feels un-win32 to double-escape every path separator, but we can always do it the unix way: /path/to/prog\ name.exe args I just tried looking at what cmd.exe does to handle the escaping, and it seems the only way to do it, is by quoting the path, like: "\path\to\prog name.exe" args or: \path\to\"prog name.exe" args The second patch (quote.diff) teaches create_child to parse double quotes. The methods are pretty much incompatible, I don't know which is better, but this being WinCE -> win32, the second should be more natural, right?. 2) If there are no args and nothing to escape, you will be left with: args = program; argslen = 0; ... and this will set wargs to the wrong thing: wargs = alloca ((argslen + 1) * sizeof (wchar_t)); mbstowcs (wargs, args, argslen + 1); What do you think of the attached patches? Cheers, Pedro Alves A few nit picky notes: - The whole file follows the GNU coding conventions. Please keep the formatting. In emacs it's easy, just ctrl-c . gnu, and tab away. I don't know in vi. - Declarations only at the start of a block in C, please. - There is a ChangeLog - use it. 2007-07-01 Pedro Alves <pedro_alves-BwYwT0D5Mwdz4s462UR3lw@xxxxxxxxxxxxxxxx> Danny Backx <dannybackx-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@xxxxxxxxxxxxxxxx> * rshd.c (create_child): Handle path escaping. Index: rshd.c =================================================================== --- rshd.c (revision 1034) +++ rshd.c (working copy) @@ -29,6 +29,7 @@ #include <stdarg.h> #include <malloc.h> #include <getopt.h> +#include <ctype.h> #include <windows.h> #include <winsock2.h> @@ -510,15 +511,34 @@ create_child (char *program, HANDLE *rea return NULL; } - argslen = 0; - args = program; - /* TODO: program paths with embedded spaces? */ - args = strchr (args, ' '); - if (args != NULL) - *args++ = '\0'; - else - args = ""; + args = ""; + + { + /* Extract path to program. The path ends at the first unescaped + space, or at the end of the string. */ + char *p, *q; + int esc = 0; + for (p = q = program; *p; p++) + { + if (!esc && isspace (*p)) + { + *p++ = '\0'; + args = p; + break; + } + else if (!esc && *p == '\\') + esc = 1; + else + { + *q++ = *p; + esc = 0; + } + } + *q = '\0'; + } + argslen = strlen (args); + wargs = alloca ((argslen + 1) * sizeof (wchar_t)); mbstowcs (wargs, args, argslen + 1); 2007-07-01 Pedro Alves <pedro_alves-BwYwT0D5Mwdz4s462UR3lw@xxxxxxxxxxxxxxxx> * rshd.c: Include ctype.h. (create_child): Handle double quoting. Index: rshd.c =================================================================== --- rshd.c (revision 1034) +++ rshd.c (working copy) @@ -29,6 +29,7 @@ #include <stdarg.h> #include <malloc.h> #include <getopt.h> +#include <ctype.h> #include <windows.h> #include <winsock2.h> @@ -510,15 +511,34 @@ create_child (char *program, HANDLE *rea return NULL; } - argslen = 0; - args = program; - /* TODO: program paths with embedded spaces? */ - args = strchr (args, ' '); - if (args != NULL) - *args++ = '\0'; - else - args = ""; + args = ""; + + { + /* Extract path to program. If the path has embedded spaces, the + user must double quote it. The path ends at the first unquoted + space, or at the end of the string. */ + char *p, *q; + int dquote = 0; + for (p = q = program; *p; p++) + { + if (!dquote && isspace (*p)) + { + *p++ = '\0'; + args = p; + break; + } + else if (!dquote && *p == '"') + dquote = 1; + else if (dquote && *p == '"') + dquote = 0; + else + *q++ = *p; + } + *q = '\0'; + } + argslen = strlen (args); + wargs = alloca ((argslen + 1) * sizeof (wchar_t)); mbstowcs (wargs, args, argslen + 1); ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/_______________________________________________ Cegcc-devel mailing list Cegcc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@xxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/cegcc-devel |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Serial port (COM1) and fileio?: 00006, Eduard Heimann |
|---|---|
| Next by Date: | Re: Small example for rshd ?: 00006, Pedro Alves |
| Previous by Thread: | Rshd - blanks in path namesi: 00006, Danny Backx |
| Next by Thread: | Re: C++ exceptions: 00006, Kevin O'Connor |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |