Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: Segfault on "zmodload -u zsh/parameter"



On Mar 5,  6:18pm, Bart Schaefer wrote:
} Subject: Segfault on "zmodload -u zsh/parameter"
}
} Latest CVS.  Appears to happen when unsetting the "parameters" parameter.

I would have thought this attracted a little more attention.

Anyway, the problem is this:

/**/
mod_export const struct gsu_hash nullsethash_gsu =
{ hashgetfn, nullsethashfn, NULL };

unsetparam_pm() unconditionally calls pm->gsu.s->unsetfn(), but in that
structure (which is duplicated in Src/params.c and Modules/parameter.c
for obscure reasons) the unsetfn is NULL, and boom.

A grep shows that the "parameters" parameter is apparently the only one
that uses this particular structure.

A lot of parameters are using this one:

/**/
mod_export const struct gsu_scalar nullsetscalar_gsu =
{ strgetfn, nullstrsetfn, NULL };

And the zsh/term* modules use:

/**/
mod_export const struct gsu_integer nullsetinteger_gsu =
{ intgetfn, NULL, NULL };

But apparently those are only used for the internal elements of hashes,
and therefore they're not called even when the hashes themselves are
unset.

Thus it doesn't seem desirable to test for null-ness of s->unsetfn in
unsetparam_pm(), but it's also unsuitable to put either nullstrsetfn
or nullintsetfn in that slot.  Hence the patch below.

Other mutterings:

Should nullnullsetfn be used in other places instead of NULL, too?

Why do we have nullstrsetfn and nullintsetfn but nullsethashfn?


Index: Src/params.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/params.c,v
retrieving revision 1.28
diff -c -r1.28 params.c
--- Src/params.c	18 Feb 2005 17:05:17 -0000	1.28
+++ Src/params.c	10 Mar 2005 16:45:52 -0000
@@ -147,7 +147,7 @@
 { hashgetfn, hashsetfn, stdunsetfn };
 /**/
 mod_export const struct gsu_hash nullsethash_gsu =
-{ hashgetfn, nullsethashfn, NULL };
+{ hashgetfn, nullsethashfn, nullnullsetfn };
 
 
 /* Non standard methods (not exported) */
@@ -2604,6 +2604,10 @@
 /**/
 void
 nullintsetfn(UNUSED(Param pm), UNUSED(zlong x))
+{}
+
+/**/
+nullnullsetfn(UNUSED(Param pm), UNUSED(int exp))
 {}
 
 
Index: Src/Modules/parameter.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/Modules/parameter.c,v
retrieving revision 1.11
diff -c -r1.11 parameter.c
--- Src/Modules/parameter.c	18 Feb 2005 17:05:18 -0000	1.11
+++ Src/Modules/parameter.c	10 Mar 2005 16:45:42 -0000
@@ -1817,7 +1817,7 @@
  * in a compile-time initialiser, so we use this instead.
  */
 static const struct gsu_hash pmnullsethash_gsu =
-{ hashgetfn, nullsethashfn, NULL };
+{ hashgetfn, nullsethashfn, nullnullsetfn };
 static const struct gsu_hash pmcommands_gsu =
 { hashgetfn, setpmcommands, stdunsetfn };
 static const struct gsu_hash pmfunctions_gsu =



Messages sorted by: Reverse Date, Date, Thread, Author