diff options
author | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2001-05-31 09:43:59 +0000 |
---|---|---|
committer | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2001-05-31 09:43:59 +0000 |
commit | 1b2d095217d1560a648032aa192057b935ce9460 (patch) | |
tree | 4126aa0dc04cde27de4cc3fe83de835190f34e71 /Src/Zle | |
parent | ae5e34db253ffd89369dd67835999c23dd9e62c2 (diff) | |
download | zsh-1b2d095217d1560a648032aa192057b935ce9460.tar.gz zsh-1b2d095217d1560a648032aa192057b935ce9460.tar.xz zsh-1b2d095217d1560a648032aa192057b935ce9460.zip |
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)
Diffstat (limited to 'Src/Zle')
-rw-r--r-- | Src/Zle/complete.c | 2 | ||||
-rw-r--r-- | Src/Zle/computil.c | 5 | ||||
-rw-r--r-- | Src/Zle/zleparameter.c | 64 |
3 files changed, 34 insertions, 37 deletions
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 5c166291e..574e638ac 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -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); diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index d7d44f999..2c0e119f9 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -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); diff --git a/Src/Zle/zleparameter.c b/Src/Zle/zleparameter.c index 8a5bc0bc2..cce421897 100644 --- a/Src/Zle/zleparameter.c +++ b/Src/Zle/zleparameter.c @@ -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 |