From 3a6a144ad682f5d4be3926676e60182588df49fa Mon Sep 17 00:00:00 2001 From: piaip Date: Mon, 22 Aug 2011 04:48:38 +0000 Subject: forbid movement ANSI escape sequence in signature files git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5385 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 46d01980..25a25976 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1440,6 +1440,28 @@ quote_strip_ansi_inline(unsigned char *is) *os = 0; } +static int +process_ansi_movecmd(char *s, int replace) { + const char *pattern_movecmd = "ABCDfjHJRu"; + const char *pattern_ansi_code = "0123456789;,["; + + while (*s) { + char *esc = strchr(s, ESC_CHR); + if (!esc) + return 0; + s = ++esc; + while (*esc && strchr(pattern_ansi_code, *esc)) + esc++; + if (strchr(pattern_movecmd, *esc)) { + if (replace == YEA) + *esc = 's'; + else + return 1; + } + } + return 0; +} + static void do_quote(void) { @@ -1795,8 +1817,10 @@ browse_sigs: if ((fs = fopen(fpath, "r"))) { fputs("\n--\n", fp); for (i = 0; i < MAX_SIGLINES && - fgets(buf, sizeof(buf), fs); i++) + fgets(buf, sizeof(buf), fs); i++) { + process_ansi_movecmd(buf, YEA); fputs(buf, fp); + } fclose(fs); fpath[i] = ch; } -- cgit v1.2.3