xenconsole: add option to avoid escape sequences in log

Add --replace-escape option to xenconsoled, which replaces ESC with
'.' in console output written to log file. This makes it slightly safer
to do tail -f on a console output of untrusted guest.
The pty output is unaffected by this option.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
[ wei: move variables into a narrower scope ]
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
Marek Marczykowski-Górecki authored and Wei Liu committed 2018-08-01 10:23:24 +01:00
1 parent 98b92f2601
commit deb0e164de
2 files changed
+33 -2

No files matched your search

+26 -1
View File
@@ -68,6 +68,7 @@ extern int log_time_hv;
extern int log_time_guest;
extern char *log_dir;
extern int discard_overflowed_data;
extern int replace_escape;
static int log_time_hv_needts = 1;
static int log_time_guest_needts = 1;
@@ -227,10 +228,34 @@ static inline int console_iter_int_arg3(struct domain *d,
return ret;
}
static void do_replace_escape(const char *src, char *dest, int len)
{
int i;
for (i = 0; i < len; i++) {
if (src[i] == '\033')
dest[i] = '.';
else
dest[i] = src[i];
}
}
static int write_all(int fd, const char* buf, size_t len)
{
while (len) {
ssize_t ret = write(fd, buf, len);
ssize_t ret;
if (replace_escape) {
char buf_replaced[1024];
size_t this_round;
if (len > sizeof(buf_replaced))
this_round = sizeof(buf_replaced);
else
this_round = len;
do_replace_escape(buf, buf_replaced, this_round);
ret = write(fd, buf_replaced, this_round);
} else
ret = write(fd, buf, len);
if (ret == -1 && errno == EINTR)
continue;
if (ret <= 0)
+7 -1
View File
@@ -40,6 +40,7 @@ int log_time_hv = 0;
int log_time_guest = 0;
char *log_dir = NULL;
int discard_overflowed_data = 1;
int replace_escape = 0;
static void handle_hup(int sig)
{
@@ -48,7 +49,8 @@ static void handle_hup(int sig)
static void usage(char *name)
{
printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all] [-o, --overflow-data=discard|keep]\n", name);
printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all] [--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all] [-o, --overflow-data=discard|keep] [--replace-escape]\n", name);
printf(" --replace-escape - replace ESC character with dot when writing console log\n");
}
static void version(char *name)
@@ -104,6 +106,7 @@ int main(int argc, char **argv)
{ "pid-file", 1, 0, 'p' },
{ "timestamp", 1, 0, 't' },
{ "overflow-data", 1, 0, 'o'},
{ "replace-escape", 0, 0, 'e'},
{ 0 },
};
bool is_interactive = false;
@@ -168,6 +171,9 @@ int main(int argc, char **argv)
discard_overflowed_data = 1;
}
break;
case 'e':
replace_escape = 1;
break;
case '?':
fprintf(stderr,
"Try `%s --help' for more information\n",
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.