From b6737eed550be93182f2ed194e836a6cbbcf4fa3 Mon Sep 17 00:00:00 2001 From: Vitezslav Crhonek Date: Mon, 28 Apr 2014 13:47:44 +0200 Subject: [PATCH] Fix segfaults if Tcl is built with stubs and Expect is used directly from C program --- expect-5.45-segfault-with-stubs.patch | 71 +++++++++++++++++++++++++++ expect.spec | 10 +++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 expect-5.45-segfault-with-stubs.patch diff --git a/expect-5.45-segfault-with-stubs.patch b/expect-5.45-segfault-with-stubs.patch new file mode 100644 index 0000000..4cfeef0 --- /dev/null +++ b/expect-5.45-segfault-with-stubs.patch @@ -0,0 +1,71 @@ +Author: Sergei Golovan +Description: This dirty hack fixes segfaults if Tcl is built with stubs + and Expect is used directly from C program. +Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588817 +Example: + #include + #include + int main() + { + FILE *pipe; + char *some_command = "uname"; + char datum; + pipe = exp_popen(some_command); + if (pipe == NULL) return 1; + while ((datum = getc (pipe)) != EOF) + printf("%c",datum); + } +Example: + #include + #include "expect.h" + main() + { + int fd = 0; + fd = exp_spawnl("echo", "echo", "Hello User: Whats up?", (char*) 0); + switch (exp_expectl(fd, exp_regexp, "ser:", 1, exp_end)) { + case 1: { + printf("GOT ser:\n"); + break; + } + default: { + printf("DEFAULT\n"); + return 1; + } + } + printf("Normal Exit\n"); + return 0; + } + +--- expect-5.45.orig/exp_clib.c ++++ expect-5.45/exp_clib.c +@@ -117,7 +117,11 @@ + #include /* for malloc */ + #endif + +-#include ++#define ckalloc(x) Tcl_Alloc(x) ++#define ckfree(x) Tcl_Free(x) ++extern char *Tcl_ErrnoMsg(int err); ++extern char *Tcl_Alloc(unsigned int size); ++extern void Tcl_Free(char *ptr); + #include "expect.h" + #define TclRegError exp_TclRegError + +@@ -389,7 +389,7 @@ + FAIL("regexp too big"); + + /* Allocate space. */ +- r = (regexp *)ckalloc(sizeof(regexp) + (unsigned)rcstate->regsize); ++ r = (regexp *)malloc(sizeof(regexp) + (unsigned)rcstate->regsize); + if (r == NULL) + FAIL("out of space"); + +@@ -399,7 +399,7 @@ + rcstate->regcode = r->program; + regc(MAGIC, rcstate); + if (reg(0, &flags, rcstate) == NULL) { +- ckfree ((char*) r); ++ free ((char*) r); + return(NULL); + } + diff --git a/expect.spec b/expect.spec index 9183638..2d67d2b 100644 --- a/expect.spec +++ b/expect.spec @@ -5,7 +5,7 @@ Summary: A program-script interaction and testing utility Name: expect Version: %{majorver} -Release: 13%{?dist} +Release: 14%{?dist} License: Public Domain Group: Development/Languages # URL: probably more useful is http://sourceforge.net/projects/expect/ @@ -25,6 +25,9 @@ Patch3: expect-5.45-match-gt-numchars-segfault.patch Patch4: expect-5.45-re-memleak.patch # Patch5: use vsnprintf instead of vsprintf to avoid buffer overflow Patch5: expect-5.45-exp-log-buf-overflow.patch +# Patch6: fixes segfaults if Tcl is built with stubs and Expect is used directly +# from C program rhbz#1091060 +Patch6: expect-5.45-segfault-with-stubs.patch # examples patches # Patch100: changes random function Patch100: expect-5.32.2-random.patch @@ -84,6 +87,7 @@ of expectk. %patch3 -p1 -b .match-gt-numchars-segfault %patch4 -p1 -b .re-memleak %patch5 -p1 -b .exp-log-buf-overflow +%patch6 -p1 -b .segfault-with-stubs # examples fixes %patch100 -p1 -b .random %patch101 -p1 -b .mkpasswd-dash @@ -173,6 +177,10 @@ rm -rf "$RPM_BUILD_ROOT" %{_mandir}/man1/tknewsbiff.1* %changelog +* Mon Apr 28 2014 Vitezslav Crhonek - 5.45-14 +- Fix segfaults if Tcl is built with stubs and Expect is used directly from C program + (patch taken from Debian project, written by Sergei Golovan) + * Thu Dec 12 2013 Vitezslav Crhonek - 5.45-13 - Use vsnprintf instead of vsprintf to avoid buffer overflow (it happens e.g. when running systemtap testsuite)