add tyfuzz utility used for fuzzing the escape code parsing routines
This commit is contained in:
parent
e81097ccf7
commit
7d46ee5062
|
@ -86,6 +86,7 @@ Makefile.in
|
|||
/src/bin/tyalpha
|
||||
/src/bin/tybg
|
||||
/src/bin/tycat
|
||||
/src/bin/tyfuzz
|
||||
/src/bin/tyls
|
||||
/src/bin/typop
|
||||
/src/bin/tyq
|
||||
|
|
|
@ -2,6 +2,9 @@ AUTOMAKE_OPTIONS = subdir-objects
|
|||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
bin_PROGRAMS = terminology tybg tyalpha typop tyq tycat tyls
|
||||
if ENABLE_FUZZING
|
||||
bin_PROGRAMS += tyfuzz
|
||||
endif
|
||||
|
||||
terminology_CPPFLAGS = -I. \
|
||||
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
|
||||
|
@ -115,3 +118,23 @@ tyls_CPPFLAGS = -I. \
|
|||
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
|
||||
|
||||
tyls_LDADD = @TERMINOLOGY_LIBS@
|
||||
|
||||
if ENABLE_FUZZING
|
||||
tyfuzz_SOURCES = \
|
||||
termptyesc.c \
|
||||
termptysave.c \
|
||||
termptyops.c \
|
||||
termptydbl.c \
|
||||
termptyext.c \
|
||||
termptygfx.c \
|
||||
termpty.c \
|
||||
config.c \
|
||||
col.c \
|
||||
tyfuzz.c
|
||||
|
||||
tyfuzz_CPPFLAGS = -I. \
|
||||
-DPACKAGE_BIN_DIR=\"$(bindir)\" -DPACKAGE_LIB_DIR=\"$(libdir)\" \
|
||||
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" @TERMINOLOGY_CFLAGS@
|
||||
|
||||
tyfuzz_LDADD = @TERMINOLOGY_LIBS@
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "string.h"
|
||||
#include "private.h"
|
||||
#include <Elementary.h>
|
||||
#include "termpty.h"
|
||||
#include <assert.h>
|
||||
|
||||
/* {{{ stub */
|
||||
int _log_domain = -1;
|
||||
static Config *_config = NULL;
|
||||
|
||||
const char *
|
||||
theme_path_get(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
main_config_sync(const Config *config)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
termio_content_change(Evas_Object *obj EINA_UNUSED,
|
||||
Evas_Coord x EINA_UNUSED, Evas_Coord y EINA_UNUSED,
|
||||
int n EINA_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Config *
|
||||
termio_config_get(const Evas_Object *obj EINA_UNUSED)
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
|
||||
void
|
||||
termio_scroll(Evas_Object *obj EINA_UNUSED,
|
||||
int direction EINA_UNUSED,
|
||||
int start_y EINA_UNUSED,
|
||||
int end_y EINA_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
/* used to set argument to evas_object_textgrid_palette_set()
|
||||
*/
|
||||
Evas_Object *
|
||||
termio_textgrid_get(Evas_Object *obj EINA_UNUSED)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
|
||||
static void
|
||||
_init_termpty(Termpty *ty)
|
||||
{
|
||||
ty->w = 80;
|
||||
ty->h = 25;
|
||||
ty->backsize = 50;
|
||||
termpty_reset_state(ty);
|
||||
ty->screen = calloc(1, sizeof(Termcell) * ty->w * ty->h);
|
||||
ty->screen2 = calloc(1, sizeof(Termcell) * ty->w * ty->h);
|
||||
assert(ty->screen);
|
||||
assert(ty->screen2);
|
||||
ty->circular_offset = 0;
|
||||
ty->fd = STDIN_FILENO;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
Termpty ty = {};
|
||||
char buf[4097];
|
||||
Eina_Unicode codepoint[4097];
|
||||
int len, i, j, k, reads;
|
||||
|
||||
eina_init();
|
||||
|
||||
_log_domain = eina_log_domain_register("tyfuzz", NULL);
|
||||
|
||||
_config = config_new();
|
||||
|
||||
_init_termpty(&ty);
|
||||
|
||||
do
|
||||
{
|
||||
char *rbuf = buf;
|
||||
len = sizeof(buf) - 1;
|
||||
|
||||
for (i = 0; i < (int)sizeof(ty.oldbuf) && ty.oldbuf[i] & 0x80; i++)
|
||||
{
|
||||
*rbuf = ty.oldbuf[i];
|
||||
rbuf++;
|
||||
len--;
|
||||
}
|
||||
len = read(ty.fd, rbuf, len);
|
||||
if (len < 0 && errno != EAGAIN)
|
||||
{
|
||||
ERR("error while reading from tty slave fd");
|
||||
break;
|
||||
}
|
||||
if (len <= 0) break;
|
||||
|
||||
for (i = 0; i < (int)sizeof(ty.oldbuf); i++)
|
||||
ty.oldbuf[i] = 0;
|
||||
|
||||
len += rbuf - buf;
|
||||
|
||||
buf[len] = 0;
|
||||
// convert UTF8 to codepoint integers
|
||||
j = 0;
|
||||
for (i = 0; i < len;)
|
||||
{
|
||||
int g = 0, prev_i = i;
|
||||
|
||||
if (buf[i])
|
||||
{
|
||||
#if (EINA_VERSION_MAJOR > 1) || (EINA_VERSION_MINOR >= 8)
|
||||
g = eina_unicode_utf8_next_get(buf, &i);
|
||||
if ((0xdc80 <= g) && (g <= 0xdcff) &&
|
||||
(len - prev_i) <= (int)sizeof(ty.oldbuf))
|
||||
#else
|
||||
i = evas_string_char_next_get(buf, i, &g);
|
||||
if (i < 0 &&
|
||||
(len - prev_i) <= (int)sizeof(ty.oldbuf))
|
||||
#endif
|
||||
{
|
||||
for (k = 0;
|
||||
(k < (int)sizeof(ty.oldbuf)) &&
|
||||
(k < (len - prev_i));
|
||||
k++)
|
||||
{
|
||||
ty.oldbuf[k] = buf[prev_i+k];
|
||||
}
|
||||
DBG("failure at %d/%d/%d", prev_i, i, len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g = 0;
|
||||
i++;
|
||||
}
|
||||
codepoint[j] = g;
|
||||
j++;
|
||||
}
|
||||
codepoint[j] = 0;
|
||||
termpty_handle_buf(&ty, codepoint, j);
|
||||
}
|
||||
while (1);
|
||||
|
||||
eina_shutdown();
|
||||
free(_config);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue