tyfuzz: read from stdin but write to /dev/null

This commit is contained in:
Boris Faure 2015-11-07 19:09:12 +01:00
parent bbb60799f4
commit a925de13dc
3 changed files with 25 additions and 8 deletions

View File

@ -909,7 +909,7 @@ termpty_write(Termpty *ty, const char *input, int len)
int fd = ty->fd; int fd = ty->fd;
#ifdef ENABLE_FUZZING #ifdef ENABLE_FUZZING
fd = STDOUT_FILENO; fd = ty->fd_dev_null;
#endif #endif
if (fd < 0) return; if (fd < 0) return;
if (write(fd, input, len) < 0) if (write(fd, input, len) < 0)

View File

@ -102,6 +102,9 @@ struct _Termpty
} backlog_beacon; } backlog_beacon;
int w, h; int w, h;
int fd, slavefd; int fd, slavefd;
#ifdef ENABLE_FUZZING
int fd_dev_null;
#endif
struct { struct {
int curid; int curid;
Eina_Hash *blocks; Eina_Hash *blocks;

View File

@ -3,12 +3,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include "string.h" #include <sys/stat.h>
#include <fcntl.h>
#include "private.h" #include "private.h"
#include <Elementary.h> #include <Elementary.h>
#include "termpty.h" #include "termpty.h"
#include "termptyops.h"
#include <assert.h> #include <assert.h>
/* {{{ stub */ /* {{{ stub */
int _log_domain = -1; int _log_domain = -1;
static Config *_config = NULL; static Config *_config = NULL;
@ -20,7 +23,7 @@ theme_path_get(void)
} }
void void
main_config_sync(const Config *config) main_config_sync(const Config *config EINA_UNUSED)
{ {
} }
@ -58,8 +61,9 @@ termio_textgrid_get(Evas_Object *obj EINA_UNUSED)
static void static void
_init_termpty(Termpty *ty) _termpty_init(Termpty *ty)
{ {
memset(ty, '\0', sizeof(*ty));
ty->w = 80; ty->w = 80;
ty->h = 25; ty->h = 25;
ty->backsize = 50; ty->backsize = 50;
@ -70,15 +74,23 @@ _init_termpty(Termpty *ty)
assert(ty->screen2); assert(ty->screen2);
ty->circular_offset = 0; ty->circular_offset = 0;
ty->fd = STDIN_FILENO; ty->fd = STDIN_FILENO;
ty->fd_dev_null = open("/dev/null", O_WRONLY|O_APPEND);
assert(ty->fd_dev_null >= 0);
}
static void
_termpty_shutdown(Termpty *ty)
{
close(ty->fd_dev_null);
} }
int int
main(int argc, char **argv) main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{ {
Termpty ty = {}; Termpty ty;
char buf[4097]; char buf[4097];
Eina_Unicode codepoint[4097]; Eina_Unicode codepoint[4097];
int len, i, j, k, reads; int len, i, j, k;
eina_init(); eina_init();
@ -86,7 +98,7 @@ main(int argc, char **argv)
_config = config_new(); _config = config_new();
_init_termpty(&ty); _termpty_init(&ty);
do do
{ {
@ -155,6 +167,8 @@ main(int argc, char **argv)
} }
while (1); while (1);
_termpty_shutdown(&ty);
eina_shutdown(); eina_shutdown();
free(_config); free(_config);