mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-26 01:32:25 +00:00
split_into_argv: stop using isspace().
I checked exhaustively today and found that the only characters (even
in Unicode) that Windows's default argv splitter will recognise as
word separators are the space and tab characters. So I think it's a
mistake to use <ctype.h> functions to identify word separators; we
should use that fixed character pair, and then we know we're getting
the right ones only.
(cherry picked from commit 9adfa79767
)
This commit is contained in:
parent
bece41ddb0
commit
bdf7f73d3d
@ -161,6 +161,11 @@
|
|||||||
#define MOD3 0
|
#define MOD3 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline bool is_word_sep(char c)
|
||||||
|
{
|
||||||
|
return c == ' ' || c == '\t';
|
||||||
|
}
|
||||||
|
|
||||||
void split_into_argv(char *cmdline, int *argc, char ***argv,
|
void split_into_argv(char *cmdline, int *argc, char ***argv,
|
||||||
char ***argstart)
|
char ***argstart)
|
||||||
{
|
{
|
||||||
@ -173,7 +178,7 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
|
|||||||
* First deal with the simplest of all special cases: if there
|
* First deal with the simplest of all special cases: if there
|
||||||
* aren't any arguments, return 0,NULL,NULL.
|
* aren't any arguments, return 0,NULL,NULL.
|
||||||
*/
|
*/
|
||||||
while (*cmdline && isspace((unsigned char)*cmdline)) cmdline++;
|
while (*cmdline && is_word_sep(*cmdline)) cmdline++;
|
||||||
if (!*cmdline) {
|
if (!*cmdline) {
|
||||||
if (argc) *argc = 0;
|
if (argc) *argc = 0;
|
||||||
if (argv) *argv = NULL;
|
if (argv) *argv = NULL;
|
||||||
@ -195,7 +200,7 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
|
|||||||
bool quote;
|
bool quote;
|
||||||
|
|
||||||
/* Skip whitespace searching for start of argument. */
|
/* Skip whitespace searching for start of argument. */
|
||||||
while (*p && isspace((unsigned char)*p)) p++;
|
while (*p && is_word_sep(*p)) p++;
|
||||||
if (!*p) break;
|
if (!*p) break;
|
||||||
|
|
||||||
/* We have an argument; start it. */
|
/* We have an argument; start it. */
|
||||||
@ -206,7 +211,7 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
|
|||||||
|
|
||||||
/* Copy data into the argument until it's finished. */
|
/* Copy data into the argument until it's finished. */
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (!quote && isspace((unsigned char)*p))
|
if (!quote && is_word_sep(*p))
|
||||||
break; /* argument is finished */
|
break; /* argument is finished */
|
||||||
|
|
||||||
if (*p == '"' || *p == '\\') {
|
if (*p == '"' || *p == '\\') {
|
||||||
|
Loading…
Reference in New Issue
Block a user