Commit dcae48e7 authored by Jakub Jirutka's avatar Jakub Jirutka

main/zsh: fix segfault when using zle-line-init in .zshrc

http://bugs.alpinelinux.org/issues/5699

The patch is backported from upstream.
parent 8dd11411
......@@ -11,7 +11,8 @@ depends=""
makedepends="ncurses-dev"
install="zsh.post-install zsh.post-upgrade zsh.pre-deinstall"
source="http://www.zsh.org/pub/$pkgname-$pkgver.tar.xz
zprofile"
zprofile
fix-zle-segfault.patch"
subpackages="$pkgname-doc"
builddir="$srcdir/$pkgname-$pkgver"
......@@ -50,8 +51,11 @@ package() {
}
md5sums="afe96fde08b70e23c1cab1ca7a68fb34 zsh-5.2.tar.xz
a5e93cd6880da04a63fc4fcaaa03987f zprofile"
a5e93cd6880da04a63fc4fcaaa03987f zprofile
1413688affa980b053dd2cdc784f8626 fix-zle-segfault.patch"
sha256sums="f17916320ffaa844bbd7ce48ceeb5945fc5f3eff64b149b4229bbfbdf3795a9d zsh-5.2.tar.xz
e3c3625d966c8277274798f26241857df5fc520e18674deba6cc356f6b022d63 zprofile"
e3c3625d966c8277274798f26241857df5fc520e18674deba6cc356f6b022d63 zprofile
7b8bfec6f7c0df6954eb27a000ff1d077e37a1ec9fd9f37c247a53922cf0c9be fix-zle-segfault.patch"
sha512sums="9938af95e09203a0a313f441e0c23279136806f6f087475ca9a66c678c57ecffc87f73ece8133a36700af8de7cb5d1bec8559eabdec2b66102062e64026c2e72 zsh-5.2.tar.xz
59182b99447872ded8adf0d890e9359ee47fce0b7acb2808f4308f945885fbf6d977a0917bbb5c0f21454caf3ba06ab092127732da4f84292d6ab0989a0110fe zprofile"
59182b99447872ded8adf0d890e9359ee47fce0b7acb2808f4308f945885fbf6d977a0917bbb5c0f21454caf3ba06ab092127732da4f84292d6ab0989a0110fe zprofile
f17016b4cb95932caabdfca273696f4a444f1e45c8e7d458db54ae12542fce87bdd6fc6c4cd070948041f50760389179c69c12296665b7b9651007faafbdbee7 fix-zle-segfault.patch"
From 0c2d823a7955981e88f7cb5b718a7081d97104f0 Mon Sep 17 00:00:00 2001
From: Peter Stephenson <pws@zsh.org>
Date: Mon, 7 Dec 2015 14:32:52 +0000
Subject: [PATCH] 37337: Delay freeing widget until not in use.
---
Alpine notes:
Fixes http://bugs.alpinelinux.org/issues/5699
---
index 2d672de..e9b1428 100644
--- a/Src/Zle/zle.h
+++ b/Src/Zle/zle.h
@@ -213,6 +213,8 @@ struct widget {
#define ZLE_KEEPSUFFIX (1<<9) /* DON'T remove added suffix */
#define ZLE_NOTCOMMAND (1<<10) /* widget should not alter lastcmd */
#define ZLE_ISCOMP (1<<11) /* usable for new style completion */
+#define WIDGET_INUSE (1<<12) /* widget is in use */
+#define WIDGET_FREE (1<<13) /* request to free when no longer in use */
/* thingies */
index 38427e8..1f0c07d 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1344,6 +1344,8 @@ execzlefunc(Thingy func, char **args, int set_bindk)
eofsent = 1;
ret = 1;
} else {
+ int inuse = wflags & WIDGET_INUSE;
+ w->flags |= WIDGET_INUSE;
if(!(wflags & ZLE_KEEPSUFFIX))
removesuffix();
if(!(wflags & ZLE_MENUCMP)) {
@@ -1367,6 +1369,12 @@ execzlefunc(Thingy func, char **args, int set_bindk)
ret = w->u.fn(args);
unqueue_signals();
}
+ if (!inuse) {
+ if (w->flags & WIDGET_FREE)
+ freewidget(w);
+ else
+ w->flags &= ~WIDGET_INUSE;
+ }
if (!(wflags & ZLE_NOTCOMMAND))
lastcmd = wflags;
}
@@ -1387,6 +1395,8 @@ execzlefunc(Thingy func, char **args, int set_bindk)
int osc = sfcontext, osi = movefd(0);
int oxt = isset(XTRACE);
LinkList largs = NULL;
+ int inuse = w->flags & WIDGET_INUSE;
+ w->flags |= WIDGET_INUSE;
if (*args) {
largs = newlinklist();
@@ -1402,8 +1412,15 @@ execzlefunc(Thingy func, char **args, int set_bindk)
opts[XTRACE] = oxt;
sfcontext = osc;
endparamscope();
- lastcmd = w->flags;
- w->flags = 0;
+ lastcmd = w->flags & ~(WIDGET_INUSE|WIDGET_FREE);
+ if (inuse) {
+ w->flags &= WIDGET_INUSE|WIDGET_FREE;
+ } else {
+ if (w->flags & WIDGET_FREE)
+ freewidget(w);
+ else
+ w->flags = 0;
+ }
r = 1;
redup(osi, 0);
}
index 271fd8e..21495b6 100644
--- a/Src/Zle/zle_thingy.c
+++ b/Src/Zle/zle_thingy.c
@@ -253,9 +253,14 @@ unbindwidget(Thingy t, int override)
/* Free a widget. */
/**/
-static void
+void
freewidget(Widget w)
{
+ if (w->flags & WIDGET_INUSE) {
+ w->flags |= WIDGET_FREE;
+ return;
+ }
+
if (w->flags & WIDGET_NCOMP) {
zsfree(w->u.comp.wid);
zsfree(w->u.comp.func);
--
2.10.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment