This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 7c220c6d38e06fa5e95102b3843aab5b6ccf4591
Author: Boris Faure <[email protected]>
AuthorDate: Tue Nov 3 16:44:27 2026 +0000
tytest_common: add tytest_common_reset()
Bring the shared Termpty back to the state tytest_common_init() leaves
it in, so that a fuzzer can run inputs one after the other in one
process, and tytest can check that an input leaves nothing behind.
It cannot be termpty_free(): with ty->pid at 0, that would
kill(0, SIGHUP) the whole process group, and free the Termpty, a static
here. The reset frees what feeding input can allocate, and restores the
colours and selections the termio stubs keep, so one input cannot
colour the next.
---
src/bin/tytest.c | 53 +++++++++++++++++++++++++++++++--
src/bin/tytest_common.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++-
src/bin/tytest_common.h | 1 +
src/bin/unit_tests.h | 1 +
4 files changed, 131 insertions(+), 3 deletions(-)
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 60a9763f..78e9f786 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -115,6 +115,7 @@ static struct {
{ "xterm_parse_color", tytest_xterm_parse_color},
{ "palette_slots", tytest_palette_slots},
{ "truecolor_cache_generation", tytest_truecolor_cache_generation},
+ { "reset", tytest_reset},
{ NULL, NULL},
};
@@ -583,7 +584,7 @@ _checksum_screen(MD5_CTX *ctx, const Termcell *cells, int w, int h)
}
static void
-_tytest_checksum(Termpty *ty)
+_tytest_checksum_hex(Termpty *ty, char *md5out)
{
MD5_CTX ctx;
Termpty_Tests tests;
@@ -591,7 +592,6 @@ _tytest_checksum(Termpty *ty)
* sub-structs would be unaligned. */
Term_State_V1 termstate;
Term_Cursor cursor_state, cursor_save0, cursor_save1;
- char md5out[(2 * MD5_HASHBYTES) + 1];
unsigned char hash[MD5_HASHBYTES];
static const char hex[] = "0123456789abcdef";
int n;
@@ -696,9 +696,58 @@ _tytest_checksum(Termpty *ty)
md5out[2 * n + 1] = hex[hash[n] & 0x0f];
}
md5out[2 * MD5_HASHBYTES] = '\0';
+}
+
+static void
+_tytest_checksum(Termpty *ty)
+{
+ char md5out[(2 * MD5_HASHBYTES) + 1];
+
+ _tytest_checksum_hex(ty, md5out);
printf("%s", md5out);
}
+/* A reset state is a fresh state: feed sequences that allocate (title,
+ * hyperlink, synchronized-update snapshot, OSC 52, backlog rows), reset,
+ * and check the checksum equals the one right after a fresh
+ * tytest_common_init(). A parse-only reset returning a different state
+ * would make fuzzer crashes depend on previous inputs. */
+int
+tytest_reset(void)
+{
+ static const char data[] =
+ "\x1b]0;hello\x07" /* sets the title */
+ "\x1b]8;;https://example.org\x1b\\link" /* allocates a hyperlink */
+ "\x1b]8;;\x1b\\"
+ "\x1b[?2026h\x1b[?2026l" /* synchronized update */
+ "\x1b]52;c;aGVsbG8=\x07" /* OSC 52 accumulation */
+ "\x1b[2Khello world\r\n的所有人类\r\n"; /* scrolls the backlog */
+ Termpty *ty;
+ char fresh[(2 * MD5_HASHBYTES) + 1];
+ char after[(2 * MD5_HASHBYTES) + 1];
+ int len = sizeof(data) - 1;
+ int i;
+
+ /* The synchronized-update watchdog runs on an ecore timer; the sync
+ * unit tests ecore_init() for the same reason. */
+ ecore_init();
+ tytest_common_init();
+ ty = tytest_termpty_get();
+ _tytest_checksum_hex(ty, fresh);
+
+ for (i = 0; i < len; i += 3)
+ tytest_common_feed(data + i, MIN(3, len - i));
+
+ tytest_common_reset();
+
+ _tytest_checksum_hex(ty, after);
+ assert(strcmp(fresh, after) == 0);
+
+ tytest_common_shutdown();
+ ecore_shutdown();
+ return 0;
+}
+
/* Render a cell's codepoint into a dump-safe form.
*
diff --git a/src/bin/tytest_common.c b/src/bin/tytest_common.c
index 46014625..04222564 100644
--- a/src/bin/tytest_common.c
+++ b/src/bin/tytest_common.c
@@ -10,6 +10,7 @@
#include <Elementary.h>
#include "termpty.h"
#include "termptynotify.h"
+#include "backlog.h"
#include "termptyops.h"
#include "termiointernals.h"
#include "utf8.h"
@@ -843,6 +844,28 @@ tytest_common_main_loop(void)
while (1);
}
+/* Restore every piece of state the parser reaches through the termio_* stubs,
+ * outside the Termpty: the palette OSC 4 overrides, the colours OSC 10/11/12
+ * set, DECSCUSR's shape and OSC 52's selections. tytest_common_init() starts
+ * from this state, so tytest_common_reset() ends there too and one fed input
+ * cannot colour the next. */
+static void
+_termio_state_reset(void)
+{
+ termio_reset_main_colors(NULL);
+ termio_palette_reset(NULL);
+ termio_remove_links(&_sd);
+ _cursor_shape = "undefined";
+ _cursor_shape_value = CURSOR_SHAPE_BLOCK;
+ free(_sel_primary);
+ _sel_primary = NULL;
+ free(_sel_clipboard);
+ _sel_clipboard = NULL;
+#if defined(BINARY_TYTEST)
+ tytest_notifications_clear();
+#endif
+}
+
void
tytest_common_init(void)
{
@@ -851,16 +874,70 @@ tytest_common_init(void)
_config->selection_escapes_read = SELECTION_READ_ALWAYS;
_sd.config = _config;
_termpty_init(&_ty, _config);
+ _termio_state_reset();
#if defined(BINARY_TYTEST)
_cells = calloc(TY_H * TY_W, sizeof(Evas_Textgrid_Cell));
assert(_cells != NULL);
#endif
}
+/* Free what _termpty_init() and the feeds allocated in the shared Termpty.
+ *
+ * This must NOT be termpty_free(): after _termpty_init()'s memset, ty->pid is
+ * 0, and termpty_free() would kill(0, SIGHUP) - the whole process group, the
+ * fuzzer included - and close ty->fd. It also frees the Termpty itself, which
+ * is a static of this module. Free by hand instead, in termpty_free()'s
+ * order. termpty_save_unregister() is skipped on purpose: _termpty_init()
+ * never registered the pty, unlike termpty_init() which only serves the real
+ * binary. */
+static void
+_termpty_release(Termpty *ty)
+{
+ Termexp *ex;
+
+ termpty_notify_free(ty);
+ free(ty->osc52_long.data);
+ EINA_LIST_FREE(ty->block.expecting, ex) free(ex);
+ if (ty->block.blocks) eina_hash_free(ty->block.blocks);
+ if (ty->block.chid_map) eina_hash_free(ty->block.chid_map);
+ if (ty->block.active) eina_list_free(ty->block.active);
+ termpty_sync_output_reset(ty);
+ eina_stringshare_del(ty->prop.title);
+ eina_stringshare_del(ty->prop.user_title);
+ eina_stringshare_del(ty->prop.icon);
+ eina_stringshare_del(ty->prop.cwd);
+ termpty_backlog_free(ty);
+ free(ty->screen);
+ free(ty->screen2);
+ if (ty->hl.links)
+ {
+ uint32_t i;
+
+ for (i = 0; i < ty->hl.size; i++)
+ term_link_free(ty, ty->hl.links + i);
+ free(ty->hl.links);
+ }
+ free(ty->hl.bitmap);
+ free(ty->buf);
+ free(ty->tabs);
+ ty_sb_free(&ty->write_buffer);
+}
+
+/* Bring the shared Termpty back to the state tytest_common_init() leaves it
+ * in, keeping ty->fd: a fuzzing loop must pay for the parser's work, not for
+ * execve() and eina_init() per input. */
+void
+tytest_common_reset(void)
+{
+ _termpty_release(&_ty);
+ _termpty_init(&_ty, _config);
+ _termio_state_reset();
+}
+
void
tytest_common_shutdown(void)
{
- termpty_notify_free(&_ty);
+ _termpty_release(&_ty);
free(_feed_buf);
_feed_buf = NULL;
free(_feed_codepoint);
diff --git a/src/bin/tytest_common.h b/src/bin/tytest_common.h
index bcc92107..ffe175f0 100644
--- a/src/bin/tytest_common.h
+++ b/src/bin/tytest_common.h
@@ -11,6 +11,7 @@
void tytest_common_main_loop(void);
void tytest_common_feed(const char *data, int datalen);
+void tytest_common_reset(void);
void tytest_common_set_chunk(int chunk);
void tytest_common_init(void);
void tytest_common_shutdown(void);
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index e9fab293..b8aed87e 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -84,6 +84,7 @@ int tytest_osc_color_name(void);
int tytest_xterm_parse_color(void);
int tytest_palette_slots(void);
int tytest_truecolor_cache_generation(void);
+int tytest_reset(void);
#endif
int tytest_keyin_legacy(void);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.