mirror of
https://github.com/zsh-users/zsh
synced 2024-07-21 10:14:19 +00:00
fix two memory leaks (at least I hope they are fixed) and some out-of-bound array accesses, plus some defensive programming for heap allocated param structs (14605)
This commit is contained in:
parent
ae5e34db25
commit
1b2d095217
|
@ -1,5 +1,11 @@
|
|||
2001-05-31 Sven Wischnowsky <wischnow@zsh.org>
|
||||
|
||||
* 14605: Src/params.c, Src/Modules/parameter.c,
|
||||
Src/Zle/complete.c, Src/Zle/computil.c, Src/Zle/zleparameter.c:
|
||||
fix two memory leaks (at least I hope they are fixed) and some
|
||||
out-of-bound array accesses, plus some defensive programming
|
||||
for heap allocated param structs
|
||||
|
||||
* 14602: Completion/Base/Utility/_values,
|
||||
Functions/Misc/nslookup: better prompt matching in nslookup;
|
||||
fix separator handling in _multi_parts
|
||||
|
|
|
@ -60,6 +60,7 @@ createspecialhash(char *name, GetNodeFunc get, ScanTabFunc scan)
|
|||
pm->sets.hfn = hashsetfn;
|
||||
pm->unsetfn = stdunsetfn;
|
||||
pm->u.hash = ht = newhashtable(0, name, NULL);
|
||||
pm->ct = 0;
|
||||
|
||||
ht->hash = hasher;
|
||||
ht->emptytable = (TableFunc) shempty;
|
||||
|
|
|
@ -403,7 +403,7 @@ parse_class(Cpattern p, unsigned char *s, unsigned char e)
|
|||
|
||||
n = !n;
|
||||
while (*s && (k || *s != e)) {
|
||||
if (s[1] == '-' && s[2] != e) {
|
||||
if (s[1] == '-' && s[2] && s[2] != e) {
|
||||
/* a run of characters */
|
||||
for (j = (int) *s; j <= (int) s[2]; j++)
|
||||
p->tab[j] = (eq ? i++ : n);
|
||||
|
|
|
@ -819,8 +819,9 @@ parse_cadef(char *nam, char **args)
|
|||
if (!multi) {
|
||||
if (!xor) {
|
||||
xor = (char **) zalloc(2 * sizeof(char *));
|
||||
xor[1] = NULL;
|
||||
xor[0] = xor[1] = NULL;
|
||||
}
|
||||
zsfree(xor[xnum]);
|
||||
xor[xnum] = ztrdup(rembslashcolon(name));
|
||||
}
|
||||
if (c == ':') {
|
||||
|
@ -1029,7 +1030,7 @@ get_cadef(char *nam, char **args)
|
|||
Cadef *p, *min, new;
|
||||
int i, na = arrlen(args);
|
||||
|
||||
for (i = MAX_CACACHE, p = cadef_cache, min = NULL; *p && i; p++, i--)
|
||||
for (i = MAX_CACACHE, p = cadef_cache, min = NULL; i && *p; p++, i--)
|
||||
if (*p && na == (*p)->ndefs && arrcmp(args, (*p)->defs)) {
|
||||
(*p)->lastt = time(0);
|
||||
|
||||
|
|
|
@ -54,7 +54,8 @@ createspecialhash(char *name, GetNodeFunc get, ScanTabFunc scan)
|
|||
pm->gets.hfn = hashgetfn;
|
||||
pm->sets.hfn = hashsetfn;
|
||||
pm->unsetfn = stdunsetfn;
|
||||
pm->u.hash = ht = newhashtable(7, name, NULL);
|
||||
pm->u.hash = ht = newhashtable(0, name, NULL);
|
||||
pm->ct = 0;
|
||||
|
||||
ht->hash = hasher;
|
||||
ht->emptytable = (TableFunc) shempty;
|
||||
|
@ -100,27 +101,24 @@ getpmwidgets(HashTable ht, char *name)
|
|||
Param pm = NULL;
|
||||
Thingy th;
|
||||
|
||||
HEAPALLOC {
|
||||
pm = (Param) zhalloc(sizeof(struct param));
|
||||
pm->nam = dupstring(name);
|
||||
pm->flags = PM_SCALAR | PM_READONLY;
|
||||
pm->sets.cfn = NULL;
|
||||
pm->gets.cfn = strgetfn;
|
||||
pm->unsetfn = NULL;
|
||||
pm->ct = 0;
|
||||
pm->env = NULL;
|
||||
pm->ename = NULL;
|
||||
pm->old = NULL;
|
||||
pm->level = 0;
|
||||
if ((th = (Thingy) thingytab->getnode(thingytab, name)) &&
|
||||
!(th->flags & DISABLED))
|
||||
pm->u.str = widgetstr(th->widget);
|
||||
else {
|
||||
pm->u.str = dupstring("");
|
||||
pm->flags |= PM_UNSET;
|
||||
}
|
||||
} LASTALLOC;
|
||||
|
||||
pm = (Param) zhalloc(sizeof(struct param));
|
||||
pm->nam = dupstring(name);
|
||||
pm->flags = PM_SCALAR | PM_READONLY;
|
||||
pm->sets.cfn = NULL;
|
||||
pm->gets.cfn = strgetfn;
|
||||
pm->unsetfn = NULL;
|
||||
pm->ct = 0;
|
||||
pm->env = NULL;
|
||||
pm->ename = NULL;
|
||||
pm->old = NULL;
|
||||
pm->level = 0;
|
||||
if ((th = (Thingy) thingytab->getnode(thingytab, name)) &&
|
||||
!(th->flags & DISABLED))
|
||||
pm->u.str = widgetstr(th->widget);
|
||||
else {
|
||||
pm->u.str = dupstring("");
|
||||
pm->flags |= PM_UNSET;
|
||||
}
|
||||
return (HashNode) pm;
|
||||
}
|
||||
|
||||
|
@ -145,7 +143,9 @@ scanpmwidgets(HashTable ht, ScanFunc func, int flags)
|
|||
for (i = 0; i < thingytab->hsize; i++)
|
||||
for (hn = thingytab->nodes[i]; hn; hn = hn->next) {
|
||||
pm.nam = hn->nam;
|
||||
if (func != scancountparams)
|
||||
if (func != scancountparams &&
|
||||
((flags & (SCANPM_WANTVALS|SCANPM_MATCHVAL)) ||
|
||||
!(flags & SCANPM_WANTKEYS)))
|
||||
pm.u.str = widgetstr(((Thingy) hn)->widget);
|
||||
func((HashNode) &pm, flags);
|
||||
}
|
||||
|
@ -185,10 +185,10 @@ struct pardef {
|
|||
};
|
||||
|
||||
static struct pardef partab[] = {
|
||||
{ "zlewidgets", PM_READONLY,
|
||||
{ "widgets", PM_READONLY,
|
||||
getpmwidgets, scanpmwidgets, hashsetfn,
|
||||
NULL, NULL, stdunsetfn, NULL },
|
||||
{ "zlekeymaps", PM_ARRAY|PM_HIDE|PM_SPECIAL|PM_READONLY,
|
||||
{ "keymaps", PM_ARRAY|PM_SPECIAL|PM_READONLY,
|
||||
NULL, NULL, NULL,
|
||||
arrsetfn, keymapsgetfn, stdunsetfn, NULL },
|
||||
{ NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
|
@ -196,14 +196,14 @@ static struct pardef partab[] = {
|
|||
|
||||
/**/
|
||||
int
|
||||
setup_zleparameter(Module m)
|
||||
setup_(Module m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**/
|
||||
int
|
||||
boot_zleparameter(Module m)
|
||||
boot_(Module m)
|
||||
{
|
||||
struct pardef *def;
|
||||
|
||||
|
@ -218,7 +218,7 @@ boot_zleparameter(Module m)
|
|||
if (def->hsetfn)
|
||||
def->pm->sets.hfn = def->hsetfn;
|
||||
} else {
|
||||
if (!(def->pm = createparam(def->name, def->flags)))
|
||||
if (!(def->pm = createparam(def->name, def->flags | PM_HIDE)))
|
||||
return 1;
|
||||
def->pm->sets.afn = def->setfn;
|
||||
def->pm->gets.afn = def->getfn;
|
||||
|
@ -228,11 +228,9 @@ boot_zleparameter(Module m)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef MODULE
|
||||
|
||||
/**/
|
||||
int
|
||||
cleanup_zleparameter(Module m)
|
||||
cleanup_(Module m)
|
||||
{
|
||||
Param pm;
|
||||
struct pardef *def;
|
||||
|
@ -249,9 +247,7 @@ cleanup_zleparameter(Module m)
|
|||
|
||||
/**/
|
||||
int
|
||||
finish_zleparameter(Module m)
|
||||
finish_(Module m)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -704,7 +704,7 @@ createparam(char *name, int flags)
|
|||
if (isset(ALLEXPORT) && !(flags & PM_HASHELEM))
|
||||
flags |= PM_EXPORTED;
|
||||
} else {
|
||||
pm = (Param) zhalloc(sizeof *pm);
|
||||
pm = (Param) hcalloc(sizeof *pm);
|
||||
pm->nam = nulstring;
|
||||
}
|
||||
pm->flags = flags & ~PM_LOCAL;
|
||||
|
@ -727,6 +727,7 @@ copyparam(Param tpm, Param pm, int toplevel)
|
|||
* with sets.?fn() usage).
|
||||
*/
|
||||
tpm->flags = pm->flags;
|
||||
tpm->ct = pm->ct;
|
||||
if (!toplevel)
|
||||
tpm->flags &= ~PM_SPECIAL;
|
||||
switch (PM_TYPE(pm->flags)) {
|
||||
|
@ -2551,6 +2552,7 @@ usernamesetfn(Param pm, char *x)
|
|||
}
|
||||
}
|
||||
#endif /* HAVE_SETUID && HAVE_GETPWNAM */
|
||||
zsfree(x);
|
||||
}
|
||||
|
||||
/* Function to get value for special parameter `UID' */
|
||||
|
|
Loading…
Reference in a new issue