From: Kamil Dudka <kdudka@redhat.com>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH 4/5] Src/module: fix use-after-free in setmathfuncs()
Date: Wed, 07 Nov 2018 15:35:52 +0100 [thread overview]
Message-ID: <5400649.Fj7YaGC3tj@kdudka-nb> (raw)
In-Reply-To: <CAHYJk3SjQ8wYbp9YdmJsW6Opkor2E=uze0MJAGfezTnXef7Rkw@mail.gmail.com>
On Wednesday, November 7, 2018 3:21:31 PM CET Mikael Magnusson wrote:
> On 11/7/18, Kamil Dudka <kdudka@redhat.com> wrote:
> > Detected by Coverity Analysis:
> >
> > Error: USE_AFTER_FREE (CWE-825):
> > zsh-5.5.1/Src/module.c:1390: freed_arg: "deletemathfunc" frees "f".
> > zsh-5.5.1/Src/module.c:1352:6: freed_arg: "zfree" frees parameter "f".
> > zsh-5.5.1/Src/mem.c:1888:5: freed_arg: "free" frees parameter "p".
> > zsh-5.5.1/Src/module.c:1394: deref_after_free: Dereferencing freed pointer
> > "f".
> > 1392| ret = 1;
> > 1393| } else {
> > 1394|-> f->flags &= ~MFF_ADDED;
> > 1395| }
> > 1396| }
> > ---
> >
> > Src/module.c | 2 --
> > 1 file changed, 2 deletions(-)
> >
> > diff --git a/Src/module.c b/Src/module.c
> > index 4ae78310f..33d75ebbd 100644
> > --- a/Src/module.c
> > +++ b/Src/module.c
> > @@ -1390,8 +1390,6 @@ setmathfuncs(char const *nam, MathFunc f, int size,
> > int *e)
> >
> > if (deletemathfunc(f)) {
> >
> > zwarnnam(nam, "math function `%s' already deleted", f->name);
> > ret = 1;
> >
> > - } else {
> > - f->flags &= ~MFF_ADDED;
> >
> > }
> >
> > }
> > f++;
> >
> > --
> > 2.17.2
>
> In the other branch, if f was already deleted, how can we use f->name there?
Do you mean deleted by the call of deletemathfunc(f) from setmathfuncs()?
If deletemathfunc(f) returns -1, it did not delete anything.
If deletemathfunc(f) returns 0, it either called free(f) or already executed:
f->flags &= ~MFF_ADDED
Executing it in setmathfuncs() again could hardly do anything useful.
It would only cause use-after-free in case f->module was true.
Kamil
next prev parent reply other threads:[~2018-11-07 14:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-07 13:04 [PATCH 1/5] Modules/clone: fix double close() Kamil Dudka
2018-11-07 13:04 ` [PATCH 2/5] Zle/computil: do not use strcpy() for overlapping blocks Kamil Dudka
2018-11-07 13:04 ` [PATCH 3/5] Src/exec: avoid fd leak on fork() failure Kamil Dudka
2018-11-07 13:04 ` [PATCH 4/5] Src/module: fix use-after-free in setmathfuncs() Kamil Dudka
2018-11-07 14:21 ` Mikael Magnusson
2018-11-07 14:35 ` Kamil Dudka [this message]
2018-11-07 13:04 ` [PATCH 5/5] Src/utils: fix memory leaks in mailstat() Kamil Dudka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5400649.Fj7YaGC3tj@kdudka-nb \
--to=kdudka@redhat.com \
--cc=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).