From e51c9c17af51e4055efb5a2cc36739d1d7ae457f Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 29 Jan 2017 08:30:14 -0800 Subject: 40453: signal handler safety for callers of patcompile(PAT_STATIC), which is not re-entrant. --- Src/Modules/zpty.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Src/Modules/zpty.c') diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index 0ef753915..2c87be16f 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -544,7 +544,8 @@ ptyread(char *nam, Ptycmd cmd, char **args, int noblock, int mustmatch) p = dupstring(args[1]); tokenize(p); remnulargs(p); - if (!(prog = patcompile(p, PAT_STATIC, NULL))) { + /* Signals handlers might stomp PAT_STATIC */ + if (!(prog = patcompile(p, PAT_ZDUP, NULL))) { zwarnnam(nam, "bad pattern: %s", args[1]); return 1; } @@ -682,9 +683,14 @@ ptyread(char *nam, Ptycmd cmd, char **args, int noblock, int mustmatch) write_loop(1, buf, used); } - if (seen && (!prog || matchok || !mustmatch)) - return 0; - return cmd->fin + 1; + { + int ret = cmd->fin + 1; + if (seen && (!prog || matchok || !mustmatch)) + ret = 0; + if (prog) + freepatprog(prog); + return ret; + } } static int -- cgit 1.4.1