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. =)
|
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))))
|
if ((pbuff >= s) && (isspace(*(pbuff - 1))))
|
||||||
pbuff--;
|
pbuff--;
|
||||||
*pbuff = 0;
|
*pbuff = 0;
|
||||||
D_STRINGS(("CondenseWhitespace() returning \"%s\"\n", s));
|
D_STRINGS(("CondenseWhitespace() returning \"%s\".\n", s));
|
||||||
return (REALLOC(s, strlen(s) + 1));
|
return (REALLOC(s, strlen(s) + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/main.h
12
src/main.h
|
@ -48,6 +48,8 @@
|
||||||
|
|
||||||
# ifndef min
|
# ifndef min
|
||||||
# define min(a,b) (((a) < (b)) ? (a) : (b))
|
# define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||||
|
# endif
|
||||||
|
# ifndef max
|
||||||
# define max(a,b) (((a) > (b)) ? (a) : (b))
|
# define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
# endif
|
# endif
|
||||||
# ifndef MIN
|
# ifndef MIN
|
||||||
|
@ -56,9 +58,13 @@
|
||||||
# ifndef MAX
|
# ifndef MAX
|
||||||
# define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
# define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
# endif
|
# endif
|
||||||
# define MAX_IT(current, other) do {if ((other) > (current)) (current) = (other);} while (0)
|
# define LOWER_BOUND(current, other) (((current) < (other)) ? ((current) = (other)) : (current))
|
||||||
# define MIN_IT(current, other) do {if ((other) < (current)) (current) = (other);} while (0)
|
# define AT_LEAST(current, other) LOWER_BOUND(current, other)
|
||||||
# define SWAP_IT(one, two, tmp) do {(tmp) = (one); (one) = (two); (two) = (tmp);} while (0)
|
# 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! */
|
/* width of scrollBar, menuBar shadow ... don't change! */
|
||||||
# define SHADOW 2
|
# define SHADOW 2
|
||||||
|
|
|
@ -1404,25 +1404,26 @@ shell_expand(char *s)
|
||||||
register unsigned long j, k, l = 0;
|
register unsigned long j, k, l = 0;
|
||||||
char new[CONFIG_BUFF];
|
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 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;
|
char *Command, *Output, *EnvVar, *OutFile;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
ASSERT(s != NULL);
|
ASSERT_RVAL(s != NULL, (char *) NULL);
|
||||||
if (!s)
|
|
||||||
return ((char *) NULL);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
new = (char *) MALLOC(CONFIG_BUFF);
|
new = (char *) MALLOC(CONFIG_BUFF);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (j = 0; *pbuff && j < CONFIG_BUFF; pbuff++, j++) {
|
for (j = 0; *pbuff && j < max; pbuff++, j++) {
|
||||||
switch (*pbuff) {
|
switch (*pbuff) {
|
||||||
case '~':
|
case '~':
|
||||||
D_OPTIONS(("Tilde detected.\n"));
|
D_OPTIONS(("Tilde detected.\n"));
|
||||||
if (eval_var) {
|
if (eval_var) {
|
||||||
strncpy(new + j, getenv("HOME"), CONFIG_BUFF - j);
|
strncpy(new + j, getenv("HOME"), max - j);
|
||||||
j += strlen(getenv("HOME")) - 1;
|
cnt1 = strlen(getenv("HOME")) - 1;
|
||||||
|
cnt2 = max - j - 1;
|
||||||
|
j += MIN(cnt1, cnt2);
|
||||||
} else {
|
} else {
|
||||||
new[j] = *pbuff;
|
new[j] = *pbuff;
|
||||||
}
|
}
|
||||||
|
@ -1506,8 +1507,9 @@ shell_expand(char *s)
|
||||||
FREE(Command);
|
FREE(Command);
|
||||||
if (Output && *Output) {
|
if (Output && *Output) {
|
||||||
l = strlen(Output) - 1;
|
l = strlen(Output) - 1;
|
||||||
strncpy(new + j, Output, CONFIG_BUFF - j);
|
strncpy(new + j, Output, max - j);
|
||||||
j += l;
|
cnt2 = max - j - 1;
|
||||||
|
j += MIN(l, cnt2);
|
||||||
FREE(Output);
|
FREE(Output);
|
||||||
} else {
|
} else {
|
||||||
j--;
|
j--;
|
||||||
|
@ -1521,7 +1523,7 @@ shell_expand(char *s)
|
||||||
if (eval_exec) {
|
if (eval_exec) {
|
||||||
Command = (char *) MALLOC(CONFIG_BUFF);
|
Command = (char *) MALLOC(CONFIG_BUFF);
|
||||||
l = 0;
|
l = 0;
|
||||||
for (pbuff++; *pbuff && *pbuff != '`' && l < CONFIG_BUFF; pbuff++, l++) {
|
for (pbuff++; *pbuff && *pbuff != '`' && l < max; pbuff++, l++) {
|
||||||
switch (*pbuff) {
|
switch (*pbuff) {
|
||||||
case '$':
|
case '$':
|
||||||
D_OPTIONS(("Environment variable detected. Evaluating.\n"));
|
D_OPTIONS(("Environment variable detected. Evaluating.\n"));
|
||||||
|
@ -1542,8 +1544,10 @@ shell_expand(char *s)
|
||||||
}
|
}
|
||||||
EnvVar[k] = 0;
|
EnvVar[k] = 0;
|
||||||
if ((tmp = getenv(EnvVar))) {
|
if ((tmp = getenv(EnvVar))) {
|
||||||
strncpy(Command + l, tmp, CONFIG_BUFF - l);
|
strncpy(Command + l, tmp, max - l);
|
||||||
l = strlen(Command) - 1;
|
cnt1 = strlen(tmp) - 1;
|
||||||
|
cnt2 = max - l - 1;
|
||||||
|
l += MIN(cnt1, cnt2);
|
||||||
}
|
}
|
||||||
pbuff--;
|
pbuff--;
|
||||||
break;
|
break;
|
||||||
|
@ -1551,10 +1555,11 @@ shell_expand(char *s)
|
||||||
Command[l] = *pbuff;
|
Command[l] = *pbuff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ASSERT(l < CONFIG_BUFF);
|
||||||
Command[l] = 0;
|
Command[l] = 0;
|
||||||
OutFile = tmpnam(NULL);
|
OutFile = tmpnam(NULL);
|
||||||
if (l + strlen(OutFile) + 8 > CONFIG_BUFF) {
|
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());
|
file_peek_path(), file_peek_line());
|
||||||
return ((char *) NULL);
|
return ((char *) NULL);
|
||||||
}
|
}
|
||||||
|
@ -1569,18 +1574,20 @@ shell_expand(char *s)
|
||||||
Output = (char *) MALLOC(fsize + 1);
|
Output = (char *) MALLOC(fsize + 1);
|
||||||
fread(Output, fsize, 1, fp);
|
fread(Output, fsize, 1, fp);
|
||||||
Output[fsize] = 0;
|
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);
|
fclose(fp);
|
||||||
remove(OutFile);
|
remove(OutFile);
|
||||||
Output = CondenseWhitespace(Output);
|
Output = CondenseWhitespace(Output);
|
||||||
strncpy(new + j, Output, CONFIG_BUFF - j);
|
strncpy(new + j, Output, max - j);
|
||||||
j += strlen(Output) - 1;
|
cnt1 = strlen(Output) - 1;
|
||||||
|
cnt2 = max - j - 1;
|
||||||
|
j += MIN(cnt1, cnt2);
|
||||||
FREE(Output);
|
FREE(Output);
|
||||||
} else {
|
} else {
|
||||||
print_warning("Command at line %lu of file %s returned no output.", file_peek_line(), file_peek_path());
|
print_warning("Command at line %lu of file %s returned no output.", file_peek_line(), file_peek_path());
|
||||||
}
|
}
|
||||||
} else {
|
} 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());
|
file_peek_line(), file_peek_path());
|
||||||
}
|
}
|
||||||
FREE(Command);
|
FREE(Command);
|
||||||
|
@ -1588,7 +1595,7 @@ shell_expand(char *s)
|
||||||
new[j] = *pbuff;
|
new[j] = *pbuff;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
print_error("warning: backquote execution support not compiled in, ignoring");
|
print_warning("Backquote execution support not compiled in, ignoring");
|
||||||
new[j] = *pbuff;
|
new[j] = *pbuff;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
@ -1612,8 +1619,10 @@ shell_expand(char *s)
|
||||||
}
|
}
|
||||||
EnvVar[k] = 0;
|
EnvVar[k] = 0;
|
||||||
if ((tmp = getenv(EnvVar))) {
|
if ((tmp = getenv(EnvVar))) {
|
||||||
strncpy(new, tmp, CONFIG_BUFF - j);
|
strncpy(new, tmp, max - j);
|
||||||
j += strlen(tmp) - 1;
|
cnt1 = strlen(tmp) - 1;
|
||||||
|
cnt2 = max - j - 1;
|
||||||
|
j += MIN(cnt1, cnt2);
|
||||||
}
|
}
|
||||||
pbuff--;
|
pbuff--;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1654,9 +1663,11 @@ shell_expand(char *s)
|
||||||
new[j] = *pbuff;
|
new[j] = *pbuff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ASSERT(j < CONFIG_BUFF);
|
||||||
new[j] = 0;
|
new[j] = 0;
|
||||||
|
|
||||||
D_PARSE(("shell_expand(%s) returning \"%s\"\n", s, new));
|
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);
|
strcpy(s, new);
|
||||||
#if 0
|
#if 0
|
||||||
|
|
Loading…
Reference in New Issue