eesh: Workaround problem with _FORTIFY_SOURCE=3

When using _FORTIFY_SOURCE=3 it appears we get like
$ eesh a b
*** buffer overflow detected ***: terminated
Aborted (core dumped)

The apparently offensive code is correct, so this must be a bug in
gcc(-13.1.1).
This commit is contained in:
Kim Woelders 2023-06-26 06:31:50 +02:00
parent 4015600f26
commit 43ef8fcfb6
1 changed files with 5 additions and 4 deletions

View File

@ -91,6 +91,7 @@ main(int argc, char **argv)
char *command, *s;
char mode;
int len, l;
const char *space;
mode = 0;
display_name = NULL;
@ -157,6 +158,7 @@ main(int argc, char **argv)
CommsSend(e, "set version 0.2");
command = NULL;
space = "";
if (i < argc)
{
mode = 1;
@ -167,13 +169,12 @@ main(int argc, char **argv)
l = strlen(s);
command = EREALLOC(char, command, len + l + 4);
if (len)
command[len++] = ' ';
if (strchr(s, ' '))
l = snprintf(command + len, l + 4, "'%s'", s);
l = snprintf(command + len, l + 4, "%s'%s'", space, s);
else
l = snprintf(command + len, l + 4, "%s", s);
l = snprintf(command + len, l + 4, "%s%s", space, s);
len += l;
space = " ";
}
}