Don't allowt '#' as a comment when it's embedded in quotes:
set something "xxx yyy # zzz" aaa shouldn't be interpreted as set something "xxx yyy" aaa
This commit is contained in:
parent
bffd29ff1c
commit
5b78bdf8aa
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=55145
@ -117,7 +117,7 @@ auth_SetPhoneList(const char *name, char *phone, int phonelen)
|
||||
continue;
|
||||
buff[strlen(buff) - 1] = '\0';
|
||||
memset(vector, '\0', sizeof vector);
|
||||
if ((n = MakeArgs(buff, vector, VECSIZE(vector), 1)) < 0)
|
||||
if ((n = MakeArgs(buff, vector, VECSIZE(vector), PARSE_REDUCE)) < 0)
|
||||
log_Printf(LogWARN, "%s: %d: Invalid line\n", SECRETFILE, lineno);
|
||||
if (n < 5)
|
||||
continue;
|
||||
@ -168,7 +168,7 @@ auth_Select(struct bundle *bundle, const char *name)
|
||||
continue;
|
||||
buff[strlen(buff) - 1] = '\0';
|
||||
memset(vector, '\0', sizeof vector);
|
||||
if ((n = MakeArgs(buff, vector, VECSIZE(vector), 1)) < 0)
|
||||
if ((n = MakeArgs(buff, vector, VECSIZE(vector), PARSE_REDUCE)) < 0)
|
||||
log_Printf(LogWARN, "%s: %d: Invalid line\n", SECRETFILE, lineno);
|
||||
if (n < 2)
|
||||
continue;
|
||||
@ -227,7 +227,7 @@ auth_Validate(struct bundle *bundle, const char *name,
|
||||
continue;
|
||||
buff[strlen(buff) - 1] = 0;
|
||||
memset(vector, '\0', sizeof vector);
|
||||
if ((n = MakeArgs(buff, vector, VECSIZE(vector), 1)) < 0)
|
||||
if ((n = MakeArgs(buff, vector, VECSIZE(vector), PARSE_REDUCE)) < 0)
|
||||
log_Printf(LogWARN, "%s: %d: Invalid line\n", SECRETFILE, lineno);
|
||||
if (n < 2)
|
||||
continue;
|
||||
@ -271,7 +271,7 @@ auth_GetSecret(struct bundle *bundle, const char *name, int len,
|
||||
if (buff[n] == '\n')
|
||||
buff[n] = '\0'; /* Trim the '\n' */
|
||||
memset(vector, '\0', sizeof vector);
|
||||
if ((n = MakeArgs(buff, vector, VECSIZE(vector), 1)) < 0)
|
||||
if ((n = MakeArgs(buff, vector, VECSIZE(vector), PARSE_REDUCE)) < 0)
|
||||
log_Printf(LogWARN, "%s: %d: Invalid line\n", SECRETFILE, lineno);
|
||||
if (n < 2)
|
||||
continue;
|
||||
|
@ -561,7 +561,7 @@ chat_Setup(struct chat *c, const char *data, const char *phone)
|
||||
} else {
|
||||
strncpy(c->script, data, sizeof c->script - 1);
|
||||
c->script[sizeof c->script - 1] = '\0';
|
||||
c->argc = MakeArgs(c->script, c->argv, VECSIZE(c->argv), 0);
|
||||
c->argc = MakeArgs(c->script, c->argv, VECSIZE(c->argv), PARSE_NOHASH);
|
||||
}
|
||||
|
||||
c->arg = -1;
|
||||
@ -702,7 +702,8 @@ ExecStr(struct physical *physical, char *command, char *out, int olen)
|
||||
int stat, nb, argc, i;
|
||||
|
||||
log_Printf(LogCHAT, "Exec: %s\n", command);
|
||||
if ((argc = MakeArgs(command, vector, VECSIZE(vector), 1)) <= 0) {
|
||||
if ((argc = MakeArgs(command, vector, VECSIZE(vector),
|
||||
PARSE_REDUCE|PARSE_NOHASH)) <= 0) {
|
||||
if (argc < 0)
|
||||
log_Printf(LogWARN, "Syntax error in exec command\n");
|
||||
*out = '\0';
|
||||
|
@ -913,7 +913,7 @@ command_Interpret(char *buff, int nb, char *argv[MAXARGS])
|
||||
cp = buff + strcspn(buff, "\r\n");
|
||||
if (cp)
|
||||
*cp = '\0';
|
||||
return MakeArgs(buff, argv, MAXARGS, 1);
|
||||
return MakeArgs(buff, argv, MAXARGS, PARSE_REDUCE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -264,14 +264,14 @@ IntToSpeed(int nspeed)
|
||||
}
|
||||
|
||||
char *
|
||||
findblank(char *p, int reduce)
|
||||
findblank(char *p, int flags)
|
||||
{
|
||||
int instring;
|
||||
|
||||
instring = 0;
|
||||
while (*p) {
|
||||
if (*p == '\\') {
|
||||
if (reduce) {
|
||||
if (flags & PARSE_REDUCE) {
|
||||
memmove(p, p + 1, strlen(p));
|
||||
if (!*p)
|
||||
break;
|
||||
@ -281,7 +281,8 @@ findblank(char *p, int reduce)
|
||||
memmove(p, p + 1, strlen(p));
|
||||
instring = !instring;
|
||||
continue;
|
||||
} else if (!instring && (issep(*p) || *p == '#'))
|
||||
} else if (!instring && (issep(*p) ||
|
||||
(*p == '#' && !(flags & PARSE_NOHASH))))
|
||||
return p;
|
||||
p++;
|
||||
}
|
||||
@ -290,7 +291,7 @@ findblank(char *p, int reduce)
|
||||
}
|
||||
|
||||
int
|
||||
MakeArgs(char *script, char **pvect, int maxargs, int reduce)
|
||||
MakeArgs(char *script, char **pvect, int maxargs, int flags)
|
||||
{
|
||||
int nargs;
|
||||
|
||||
@ -302,7 +303,7 @@ MakeArgs(char *script, char **pvect, int maxargs, int reduce)
|
||||
break;
|
||||
*pvect++ = script;
|
||||
nargs++;
|
||||
script = findblank(script, reduce);
|
||||
script = findblank(script, flags);
|
||||
if (script == NULL)
|
||||
return -1;
|
||||
else if (*script == '#')
|
||||
|
@ -91,6 +91,11 @@
|
||||
#define PHYS_FOREGROUND 64 /* Pseudo mode, same as background */
|
||||
#define PHYS_ALL 127
|
||||
|
||||
/* flags passed to findblank() and MakeArgs() */
|
||||
#define PARSE_NORMAL 0
|
||||
#define PARSE_REDUCE 1
|
||||
#define PARSE_NOHASH 2
|
||||
|
||||
extern void randinit(void);
|
||||
extern ssize_t fullread(int, void *, size_t);
|
||||
extern const char *mode2Nam(int);
|
||||
|
@ -141,7 +141,8 @@ exec_Create(struct physical *p)
|
||||
|
||||
log_Printf(LogDEBUG, "Exec'ing ``%s''\n", p->name.base);
|
||||
|
||||
if ((argc = MakeArgs(p->name.base, argv, VECSIZE(argv), 1)) < 0) {
|
||||
if ((argc = MakeArgs(p->name.base, argv, VECSIZE(argv),
|
||||
PARSE_REDUCE|PARSE_NOHASH)) < 0) {
|
||||
log_Printf(LogWARN, "Syntax error in exec command\n");
|
||||
_exit(127);
|
||||
}
|
||||
|
@ -265,28 +265,22 @@ xgets(char *buf, int buflen, FILE *fp)
|
||||
static char *
|
||||
GetLabel(char *line, const char *filename, int linenum)
|
||||
{
|
||||
char *wp;
|
||||
char *argv[MAXARGS];
|
||||
int argc, len;
|
||||
|
||||
if ((wp = findblank(line, 1)) != NULL) {
|
||||
while (issep(*wp))
|
||||
*wp++ = '\0';
|
||||
if (*wp == '#')
|
||||
*wp = '\0';
|
||||
if (*wp != '\0') {
|
||||
log_Printf(LogWARN, "Bad label in %s (line %d) - too many words.\n",
|
||||
filename, linenum);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
wp = strchr(line, ':');
|
||||
if (wp == NULL || wp[1] != '\0') {
|
||||
log_Printf(LogWARN, "Bad rule in %s (line %d) - missing colon.\n",
|
||||
argc = MakeArgs(line, argv, MAXARGS, PARSE_REDUCE);
|
||||
|
||||
if (argc == 2 && !strcmp(argv[1], ":"))
|
||||
return argv[0];
|
||||
|
||||
if (argc != 1 || (len = strlen(argv[0])) < 2 || argv[0][len-1] != ':') {
|
||||
log_Printf(LogWARN, "Bad label in %s (line %d) - missing colon\n",
|
||||
filename, linenum);
|
||||
return NULL;
|
||||
}
|
||||
*wp = '\0';
|
||||
argv[0][len-1] = '\0'; /* Lose the ':' */
|
||||
|
||||
return line;
|
||||
return argv[0];
|
||||
}
|
||||
|
||||
/* Returns -2 for ``file not found'' and -1 for ``label not found'' */
|
||||
@ -349,7 +343,6 @@ ReadSystem(struct bundle *bundle, const char *name, const char *file,
|
||||
default:
|
||||
if ((cp = GetLabel(cp, filename, linenum)) == NULL)
|
||||
continue;
|
||||
cp = strip(cp); /* lose any spaces between the label and the ':' */
|
||||
|
||||
if (strcmp(cp, name) == 0) {
|
||||
/* We're in business */
|
||||
@ -365,7 +358,7 @@ ReadSystem(struct bundle *bundle, const char *name, const char *file,
|
||||
|
||||
if (!indent) { /* start of next section */
|
||||
if (*cp != '!' && how == SYSTEM_EXEC)
|
||||
GetLabel(cp, filename, linenum);
|
||||
cp = GetLabel(cp, filename, linenum);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user