From: "Anders Kaseorg" <andersk@mit.edu>
To: Herbert Xu <herbert@gondor.apana.org.au>,
Vladimir Kudrya <vladimir.csp@gmail.com>
Cc: dash@vger.kernel.org
Subject: Re: [PATCH] var: Call setlocale when LC variables are set
Date: Wed, 11 Nov 2026 00:36:25 -0800 [thread overview]
Message-ID: <6e24ef04-bdbe-4d7c-9ed4-993735c2439e@mit.edu> (raw)
In-Reply-To: <ai1MN3hk3ihI7FBf@gondor.apana.org.au>
On 6/13/26 05:25, Herbert Xu wrote:
> @@ -101,6 +108,11 @@ struct var varinit[] = {
> { 0, VSTRFIXED|VTEXTFIXED|VUNSET, "TERM\0", 0 },
> { 0, VSTRFIXED|VTEXTFIXED|VUNSET, "HISTSIZE\0", sethistsize },
> #endif
> + { 0, VSTRFIXED|VTEXTFIXED|VFULL|VUNSET, "LC_ALL\0", changelocale },
> + { 0, VSTRFIXED|VTEXTFIXED|VFULL|VUNSET, "LC_COLLATE\0", changelocale },
> + { 0, VSTRFIXED|VTEXTFIXED|VFULL|VUNSET, "LC_CTYPE\0", changelocale },
> + { 0, VSTRFIXED|VTEXTFIXED|VFULL|VUNSET, "LC_NUMERIC\0", changelocale },
> + { 0, VSTRFIXED|VTEXTFIXED|VFULL|VUNSET, "LANG\0", changelocale },
When one of these variables is unset, setvareq() drops VFULL from the
flags here:
else if ((vp->flags & VSTRFIXED))
bits = VSTRFIXED;
So the setlocale() call is unexpectedly skipped.
> @@ -299,8 +324,8 @@ out_free:
> vp->text = s;
> vp->flags = flags;
>
> - if (vp->func && (flags & VNOFUNC) == 0)
> - (*vp->func)(varnull(s));
> + if (!(flags & VNOFUNC))
> + varfunc(vp);
Since vp->text was already freed above, this leads to a use-after-free.
> @@ -536,8 +561,8 @@ poplocalvars(void)
> ckfree(vp->text);
> vp->flags = lvp->flags;
> vp->text = lvp->text;
> - if (vp->func && !(vp->flags & VNOFUNC))
> - (*vp->func)(varnull(vp->text));
> + if (!(vp->flags & VNOFUNC))
> + varfunc(vp);
Here as well: since vp->text was already freed above, this leads to a
use-after-free.
Reproduction:
$ export LANG=C.UTF-8
$ dash -c 'x=ëë; LC_ALL=C; echo ${#x}; unset LC_ALL; echo ${#x};
LC_ALL=C; echo ${#x}'
4
2
2
(Expected 4 2 4.)
Anders
prev parent reply other threads:[~2026-11-11 8:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 21:56 Single-byte operations on vars broken Vladimir Kudrya
2026-06-13 12:25 ` [PATCH] var: Call setlocale when LC variables are set Herbert Xu
2026-11-11 8:36 ` Anders Kaseorg [this message]
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=6e24ef04-bdbe-4d7c-9ed4-993735c2439e@mit.edu \
--to=andersk@mit.edu \
--cc=dash@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=vladimir.csp@gmail.com \
/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