From: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
To: Ahmad Gani <reyuki@gnuweeb.org>
Cc: Ammar Faizi <ammarfaizi2@gnuweeb.org>,
"GNU/Weeb Mailing List" <gwml@vger.gnuweeb.org>
Subject: Re: [PATCH gwproxy v9 2/2] gwproxy: refactor code base to add experimental raw DNS backend
Date: Wed, 10 Sep 2025 17:00:51 +0700 [thread overview]
Message-ID: <CAOG64qNbY_9JOXJy=VodkHTgTV4MExVdAFWan-XC-ed=bPWoAQ@mail.gmail.com> (raw)
In-Reply-To: <20250910030512.551673-3-reyuki@gnuweeb.org>
On Wed, Sep 10, 2025 at 10:07 AM Ahmad Gani wrote:
> + cfg = &w->ctx->cfg;
> + resolv = &w->dns_resolver;
> + p1 = realloc(resolv->stack.arr, cfg->sess_map_cap * sizeof(*resolv->stack.arr));
> + if (!p1)
> + return;
> + p2 = realloc(resolv->sess_map, cfg->sess_map_cap * sizeof(*resolv->sess_map));
> + if (!p2)
> + return;
This is absolutely stupid. You're messing with a simple C object
without understanding even the basics regarding their handling.
Just because it's a shrink operation, it doesn't mean realloc() will
always spit out the same pointer you fed it.
If "realloc(X, new_size)" succeeds, there's no guarantee the returned
pointer matches the one you passed. 'X' could be invalid after the
realloc() call.
So, if "p2 = realloc()" fails, you could be leaking p1, and
->stack.arr might be invalid too, yet it's still used. Clearly, this
one mistake results in double bugs, use-after-free and memory leak,
because realloc() might free the pointer you gave it and allocate a
new memory area with a different address.
--
Software Engineer & ITPM Officer
Alviro Iskandar Setiawan
+1 908 777 0074
next prev parent reply other threads:[~2025-09-10 10:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-10 3:05 [PATCH gwproxy v9 0/2] Initial work on integration of DNS parser lib in gwproxy Ahmad Gani
2025-09-10 3:05 ` [PATCH gwproxy v9 1/2] dnsparser: Add dns parser code Ahmad Gani
2025-09-10 3:05 ` [PATCH gwproxy v9 2/2] gwproxy: refactor code base to add experimental raw DNS backend Ahmad Gani
2025-09-10 10:00 ` Alviro Iskandar Setiawan [this message]
2025-09-10 10:28 ` Ahmad Gani
2025-09-10 10:05 ` Alviro Iskandar Setiawan
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='CAOG64qNbY_9JOXJy=VodkHTgTV4MExVdAFWan-XC-ed=bPWoAQ@mail.gmail.com' \
--to=alviro.iskandar@gnuweeb.org \
--cc=ammarfaizi2@gnuweeb.org \
--cc=gwml@vger.gnuweeb.org \
--cc=reyuki@gnuweeb.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox