(termio): Fix crash bug: when input line starts with '?', `s' was used
uninitialized. (buf, exec, termio): Make buf[] and exec[] local to termio().
This commit is contained in:
parent
8f74995e99
commit
e56ffad8be
3 changed files with 8 additions and 15 deletions
|
@ -43,17 +43,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct tagstruct *taglist;
|
struct tagstruct *taglist;
|
||||||
s_char buf[4096];
|
|
||||||
s_char exec[8];
|
|
||||||
static unsigned short tagnum;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
io_init(void)
|
io_init(void)
|
||||||
{
|
{
|
||||||
taglist = NULL;
|
taglist = NULL;
|
||||||
buf[0] = 0;
|
|
||||||
tagnum = 0;
|
|
||||||
sprintf(exec, "execute");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s_char *
|
s_char *
|
||||||
|
|
|
@ -40,8 +40,6 @@ struct tagstruct {
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct tagstruct *taglist;
|
extern struct tagstruct *taglist;
|
||||||
extern s_char buf[4096];
|
|
||||||
extern s_char exec[8];
|
|
||||||
|
|
||||||
void io_init(void);
|
void io_init(void);
|
||||||
s_char *gettag(s_char *p);
|
s_char *gettag(s_char *p);
|
||||||
|
|
|
@ -47,12 +47,14 @@
|
||||||
int
|
int
|
||||||
termio(int fd, int sock, FILE *auxfi)
|
termio(int fd, int sock, FILE *auxfi)
|
||||||
{
|
{
|
||||||
|
static char exec[] = "execute";
|
||||||
|
static char buf[4096];
|
||||||
s_char out[4096];
|
s_char out[4096];
|
||||||
int i, n;
|
int i, n;
|
||||||
s_char *ptr;
|
s_char *ptr;
|
||||||
s_char *p, *q, *r, *s, *t;
|
s_char *p, *q, *r, *s, *t;
|
||||||
int nbytes;
|
int nbytes;
|
||||||
int numarg, prespace, exec_com, inarg, quoted, tagging;
|
int prespace, exec_com, inarg, quoted, tagging;
|
||||||
struct tagstruct *tag;
|
struct tagstruct *tag;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
char c;
|
char c;
|
||||||
|
@ -123,11 +125,11 @@ termio(int fd, int sock, FILE *auxfi)
|
||||||
p = buf;
|
p = buf;
|
||||||
q = out;
|
q = out;
|
||||||
r = out;
|
r = out;
|
||||||
numarg = 0;
|
|
||||||
tagging = 0;
|
tagging = 0;
|
||||||
inarg = 0;
|
inarg = 0;
|
||||||
prespace = 1;
|
prespace = 1;
|
||||||
quoted = 0;
|
quoted = 0;
|
||||||
|
exec_com = 0;
|
||||||
while (p < buf + n && q < out + 4000) {
|
while (p < buf + n && q < out + 4000) {
|
||||||
if (*p == '\n') {
|
if (*p == '\n') {
|
||||||
if (tagging) {
|
if (tagging) {
|
||||||
|
@ -141,11 +143,11 @@ termio(int fd, int sock, FILE *auxfi)
|
||||||
*t = 0;
|
*t = 0;
|
||||||
}
|
}
|
||||||
*q++ = *p++;
|
*q++ = *p++;
|
||||||
numarg = 0;
|
|
||||||
tagging = 0;
|
tagging = 0;
|
||||||
inarg = 0;
|
inarg = 0;
|
||||||
prespace = 1;
|
prespace = 1;
|
||||||
quoted = 0;
|
quoted = 0;
|
||||||
|
exec_com = 0;
|
||||||
ptr = p;
|
ptr = p;
|
||||||
r = q;
|
r = q;
|
||||||
} else if (tagging) {
|
} else if (tagging) {
|
||||||
|
@ -153,7 +155,7 @@ termio(int fd, int sock, FILE *auxfi)
|
||||||
} else if (!quoted && isspace(*p)) {
|
} else if (!quoted && isspace(*p)) {
|
||||||
*q++ = *p++;
|
*q++ = *p++;
|
||||||
prespace = 1;
|
prespace = 1;
|
||||||
if (numarg == 1 && exec_com && s > exec + 2) {
|
if (exec_com && s > exec + 2) {
|
||||||
tagging = 1;
|
tagging = 1;
|
||||||
s = p;
|
s = p;
|
||||||
}
|
}
|
||||||
|
@ -175,10 +177,9 @@ termio(int fd, int sock, FILE *auxfi)
|
||||||
if (!inarg && *p != '?') {
|
if (!inarg && *p != '?') {
|
||||||
s = exec;
|
s = exec;
|
||||||
exec_com = 1;
|
exec_com = 1;
|
||||||
numarg++;
|
inarg = 1;
|
||||||
}
|
}
|
||||||
inarg = 1;
|
if (exec_com && *s && *s++ != *p)
|
||||||
if (*s && *s++ != *p)
|
|
||||||
exec_com = 0;
|
exec_com = 0;
|
||||||
}
|
}
|
||||||
*q++ = *p++;
|
*q++ = *p++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue