Tue Sep 28 18:54:16 PDT 1999 Michael Jennings <mej@eterm.org>
The config parser is now much more bullet-proof. A pixmaps.list file with too many entries will no longer crash Eterm. SVN revision: 450
This commit is contained in:
parent
3630db17ab
commit
35356e00f0
|
@ -2500,3 +2500,9 @@ Tue Sep 28 14:18:44 PDT 1999 Michael Jennings <mej@eterm.org>
|
|||
ago. Oopsie. =)
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Tue Sep 28 18:54:16 PDT 1999 Michael Jennings <mej@eterm.org>
|
||||
|
||||
The config parser is now much more bullet-proof. A pixmaps.list file
|
||||
with too many entries will no longer crash Eterm.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
|
|
@ -552,7 +552,7 @@ CondenseWhitespace(char *s)
|
|||
if ((pbuff >= s) && (isspace(*(pbuff - 1))))
|
||||
pbuff--;
|
||||
*pbuff = 0;
|
||||
D_STRINGS(("CondenseWhitespace() returning \"%s\"\n", s));
|
||||
D_STRINGS(("CondenseWhitespace() returning \"%s\".\n", s));
|
||||
return (REALLOC(s, strlen(s) + 1));
|
||||
}
|
||||
|
||||
|
|
12
src/main.h
12
src/main.h
|
@ -48,6 +48,8 @@
|
|||
|
||||
# ifndef min
|
||||
# define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
# endif
|
||||
# ifndef max
|
||||
# define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
# endif
|
||||
# ifndef MIN
|
||||
|
@ -56,9 +58,13 @@
|
|||
# ifndef MAX
|
||||
# define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
# endif
|
||||
# define MAX_IT(current, other) do {if ((other) > (current)) (current) = (other);} while (0)
|
||||
# define MIN_IT(current, other) do {if ((other) < (current)) (current) = (other);} while (0)
|
||||
# define SWAP_IT(one, two, tmp) do {(tmp) = (one); (one) = (two); (two) = (tmp);} while (0)
|
||||
# define LOWER_BOUND(current, other) (((current) < (other)) ? ((current) = (other)) : (current))
|
||||
# define AT_LEAST(current, other) LOWER_BOUND(current, other)
|
||||
# define MAX_IT(current, other) LOWER_BOUND(current, other)
|
||||
# define UPPER_BOUND(current, other) (((current) > (other)) ? ((current) = (other)) : (current))
|
||||
# define AT_MOST(current, other) UPPER_BOUND(current, other)
|
||||
# define MIN_IT(current, other) UPPER_BOUND(current, other)
|
||||
# define SWAP_IT(one, two, tmp) do {(tmp) = (one); (one) = (two); (two) = (tmp);} while (0)
|
||||
|
||||
/* width of scrollBar, menuBar shadow ... don't change! */
|
||||
# define SHADOW 2
|
||||
|
|
|
@ -1404,25 +1404,26 @@ shell_expand(char *s)
|
|||
register unsigned long j, k, l = 0;
|
||||
char new[CONFIG_BUFF];
|
||||
unsigned char eval_escape = 1, eval_var = 1, eval_exec = 1, eval_func = 1, in_single = 0, in_double = 0;
|
||||
unsigned long fsize;
|
||||
unsigned long fsize, cnt1 = 0, cnt2 = 0;
|
||||
const unsigned long max = CONFIG_BUFF - 1;
|
||||
char *Command, *Output, *EnvVar, *OutFile;
|
||||
FILE *fp;
|
||||
|
||||
ASSERT(s != NULL);
|
||||
if (!s)
|
||||
return ((char *) NULL);
|
||||
ASSERT_RVAL(s != NULL, (char *) NULL);
|
||||
|
||||
#if 0
|
||||
new = (char *) MALLOC(CONFIG_BUFF);
|
||||
#endif
|
||||
|
||||
for (j = 0; *pbuff && j < CONFIG_BUFF; pbuff++, j++) {
|
||||
for (j = 0; *pbuff && j < max; pbuff++, j++) {
|
||||
switch (*pbuff) {
|
||||
case '~':
|
||||
D_OPTIONS(("Tilde detected.\n"));
|
||||
if (eval_var) {
|
||||
strncpy(new + j, getenv("HOME"), CONFIG_BUFF - j);
|
||||
j += strlen(getenv("HOME")) - 1;
|
||||
strncpy(new + j, getenv("HOME"), max - j);
|
||||
cnt1 = strlen(getenv("HOME")) - 1;
|
||||
cnt2 = max - j - 1;
|
||||
j += MIN(cnt1, cnt2);
|
||||
} else {
|
||||
new[j] = *pbuff;
|
||||
}
|
||||
|
@ -1506,8 +1507,9 @@ shell_expand(char *s)
|
|||
FREE(Command);
|
||||
if (Output && *Output) {
|
||||
l = strlen(Output) - 1;
|
||||
strncpy(new + j, Output, CONFIG_BUFF - j);
|
||||
j += l;
|
||||
strncpy(new + j, Output, max - j);
|
||||
cnt2 = max - j - 1;
|
||||
j += MIN(l, cnt2);
|
||||
FREE(Output);
|
||||
} else {
|
||||
j--;
|
||||
|
@ -1521,7 +1523,7 @@ shell_expand(char *s)
|
|||
if (eval_exec) {
|
||||
Command = (char *) MALLOC(CONFIG_BUFF);
|
||||
l = 0;
|
||||
for (pbuff++; *pbuff && *pbuff != '`' && l < CONFIG_BUFF; pbuff++, l++) {
|
||||
for (pbuff++; *pbuff && *pbuff != '`' && l < max; pbuff++, l++) {
|
||||
switch (*pbuff) {
|
||||
case '$':
|
||||
D_OPTIONS(("Environment variable detected. Evaluating.\n"));
|
||||
|
@ -1542,8 +1544,10 @@ shell_expand(char *s)
|
|||
}
|
||||
EnvVar[k] = 0;
|
||||
if ((tmp = getenv(EnvVar))) {
|
||||
strncpy(Command + l, tmp, CONFIG_BUFF - l);
|
||||
l = strlen(Command) - 1;
|
||||
strncpy(Command + l, tmp, max - l);
|
||||
cnt1 = strlen(tmp) - 1;
|
||||
cnt2 = max - l - 1;
|
||||
l += MIN(cnt1, cnt2);
|
||||
}
|
||||
pbuff--;
|
||||
break;
|
||||
|
@ -1551,10 +1555,11 @@ shell_expand(char *s)
|
|||
Command[l] = *pbuff;
|
||||
}
|
||||
}
|
||||
ASSERT(l < CONFIG_BUFF);
|
||||
Command[l] = 0;
|
||||
OutFile = tmpnam(NULL);
|
||||
if (l + strlen(OutFile) + 8 > CONFIG_BUFF) {
|
||||
print_error("parse error in file %s, line %lu: Cannot execute command, line too long",
|
||||
print_error("Parse error in file %s, line %lu: Cannot execute command, line too long",
|
||||
file_peek_path(), file_peek_line());
|
||||
return ((char *) NULL);
|
||||
}
|
||||
|
@ -1569,18 +1574,20 @@ shell_expand(char *s)
|
|||
Output = (char *) MALLOC(fsize + 1);
|
||||
fread(Output, fsize, 1, fp);
|
||||
Output[fsize] = 0;
|
||||
D_PARSE(("Command returned \"%s\"\n", Output));
|
||||
D_ENL(("Command returned \"%s\". Output length is %lu, j = %lu, max - j == %lu\n", Output, fsize, j, max - j));
|
||||
fclose(fp);
|
||||
remove(OutFile);
|
||||
Output = CondenseWhitespace(Output);
|
||||
strncpy(new + j, Output, CONFIG_BUFF - j);
|
||||
j += strlen(Output) - 1;
|
||||
strncpy(new + j, Output, max - j);
|
||||
cnt1 = strlen(Output) - 1;
|
||||
cnt2 = max - j - 1;
|
||||
j += MIN(cnt1, cnt2);
|
||||
FREE(Output);
|
||||
} else {
|
||||
print_warning("Command at line %lu of file %s returned no output.", file_peek_line(), file_peek_path());
|
||||
}
|
||||
} else {
|
||||
print_warning("Output file %s could not be created. (line %lu of file %s)", (OutFile ? OutFile : "(null)"),
|
||||
print_warning("Output file %s could not be created. (line %lu of file %s)", NONULL(OutFile),
|
||||
file_peek_line(), file_peek_path());
|
||||
}
|
||||
FREE(Command);
|
||||
|
@ -1588,7 +1595,7 @@ shell_expand(char *s)
|
|||
new[j] = *pbuff;
|
||||
}
|
||||
#else
|
||||
print_error("warning: backquote execution support not compiled in, ignoring");
|
||||
print_warning("Backquote execution support not compiled in, ignoring");
|
||||
new[j] = *pbuff;
|
||||
#endif
|
||||
break;
|
||||
|
@ -1612,8 +1619,10 @@ shell_expand(char *s)
|
|||
}
|
||||
EnvVar[k] = 0;
|
||||
if ((tmp = getenv(EnvVar))) {
|
||||
strncpy(new, tmp, CONFIG_BUFF - j);
|
||||
j += strlen(tmp) - 1;
|
||||
strncpy(new, tmp, max - j);
|
||||
cnt1 = strlen(tmp) - 1;
|
||||
cnt2 = max - j - 1;
|
||||
j += MIN(cnt1, cnt2);
|
||||
}
|
||||
pbuff--;
|
||||
} else {
|
||||
|
@ -1654,9 +1663,11 @@ shell_expand(char *s)
|
|||
new[j] = *pbuff;
|
||||
}
|
||||
}
|
||||
ASSERT(j < CONFIG_BUFF);
|
||||
new[j] = 0;
|
||||
|
||||
D_PARSE(("shell_expand(%s) returning \"%s\"\n", s, new));
|
||||
D_PARSE((" strlen(s) == %lu, strlen(new) == %lu, j == %lu\n", strlen(s), strlen(new), j));
|
||||
|
||||
strcpy(s, new);
|
||||
#if 0
|
||||
|
|
Loading…
Reference in New Issue