* [musl] [PATCH] src: locale: fix potential NULL dereference in iconv() in
@ 2025-02-17 15:18 Anton Moryakov
2025-02-17 15:37 ` Yao Zi
0 siblings, 1 reply; 5+ messages in thread
From: Anton Moryakov @ 2025-02-17 15:18 UTC (permalink / raw)
To: musl; +Cc: Anton Moryakov
Fixed a potential NULL dereference in iconv() by adding a check before
accessing scd->state. If scd remains NULL due to cd & 1 != 0,
dereferencing scd->state would cause undefined behavior.
Previous code:
switch (scd->state) { // Potential NULL dereference
Fixed code:
if (scd == NULL)
goto ilseq;
switch (scd->state) {
This ensures that scd is properly validated before usage, preventing crashes.
Although the situation where scd == NULL is unlikely, I would recommend adding this check
Triggers found by static analyzer Svace.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
src/locale/iconv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/locale/iconv.c b/src/locale/iconv.c
index 52178950..ea3e8be1 100644
--- a/src/locale/iconv.c
+++ b/src/locale/iconv.c
@@ -380,6 +380,8 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
}
goto ilseq;
}
+ if(scd == NULL)
+ goto ilseq;
switch (scd->state) {
case 1:
if (c=='\\') c = 0xa5;
--
2.30.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] [PATCH] src: locale: fix potential NULL dereference in iconv() in
2025-02-17 15:18 [musl] [PATCH] src: locale: fix potential NULL dereference in iconv() in Anton Moryakov
@ 2025-02-17 15:37 ` Yao Zi
2025-02-17 15:50 ` Anton Moryakov
0 siblings, 1 reply; 5+ messages in thread
From: Yao Zi @ 2025-02-17 15:37 UTC (permalink / raw)
To: musl; +Cc: Anton Moryakov
On Mon, Feb 17, 2025 at 06:18:18PM +0300, Anton Moryakov wrote:
> Fixed a potential NULL dereference in iconv() by adding a check before
> accessing scd->state. If scd remains NULL due to cd & 1 != 0,
> dereferencing scd->state would cause undefined behavior.
>
> Previous code:
> switch (scd->state) { // Potential NULL dereference
>
> Fixed code:
> if (scd == NULL)
> goto ilseq;
> switch (scd->state) {
>
> This ensures that scd is properly validated before usage, preventing crashes.
> Although the situation where scd == NULL is unlikely, I would recommend adding this check
Why is the check necessary? I cannot find out a valid use case that the
scd pointer is NULL when converting from ISO2022_JP.
Please have a look at iconv_open().
Thanks,
Yao Zi
> Triggers found by static analyzer Svace.
>
> Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
>
> ---
> src/locale/iconv.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/src/locale/iconv.c b/src/locale/iconv.c
> index 52178950..ea3e8be1 100644
> --- a/src/locale/iconv.c
> +++ b/src/locale/iconv.c
> @@ -380,6 +380,8 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
> }
> goto ilseq;
> }
> + if(scd == NULL)
> + goto ilseq;
> switch (scd->state) {
> case 1:
> if (c=='\\') c = 0xa5;
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] [PATCH] src: locale: fix potential NULL dereference in iconv() in
2025-02-17 15:37 ` Yao Zi
@ 2025-02-17 15:50 ` Anton Moryakov
2025-02-17 21:50 ` Thorsten Glaser
2025-02-17 23:17 ` Rich Felker
0 siblings, 2 replies; 5+ messages in thread
From: Anton Moryakov @ 2025-02-17 15:50 UTC (permalink / raw)
To: Yao Zi; +Cc: musl
[-- Attachment #1: Type: text/plain, Size: 1792 bytes --]
Thanks for the feedback!
пн, 17 февр. 2025 г. в 18:38, Yao Zi <ziyao@disroot.org>:
> On Mon, Feb 17, 2025 at 06:18:18PM +0300, Anton Moryakov wrote:
> > Fixed a potential NULL dereference in iconv() by adding a check before
> > accessing scd->state. If scd remains NULL due to cd & 1 != 0,
> > dereferencing scd->state would cause undefined behavior.
> >
> > Previous code:
> > switch (scd->state) { // Potential NULL dereference
> >
> > Fixed code:
> > if (scd == NULL)
> > goto ilseq;
> > switch (scd->state) {
> >
> > This ensures that scd is properly validated before usage, preventing
> crashes.
> > Although the situation where scd == NULL is unlikely, I would recommend
> adding this check
>
> Why is the check necessary? I cannot find out a valid use case that the
> scd pointer is NULL when converting from ISO2022_JP.
>
> Please have a look at iconv_open().
>
> Thanks,
> Yao Zi
>
> > Triggers found by static analyzer Svace.
> >
> > Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
> >
> > ---
> > src/locale/iconv.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/src/locale/iconv.c b/src/locale/iconv.c
> > index 52178950..ea3e8be1 100644
> > --- a/src/locale/iconv.c
> > +++ b/src/locale/iconv.c
> > @@ -380,6 +380,8 @@ size_t iconv(iconv_t cd, char **restrict in, size_t
> *restrict inb, char **restri
> > }
> > goto ilseq;
> > }
> > + if(scd == NULL)
> > + goto ilseq;
> > switch (scd->state) {
> > case 1:
> > if (c=='\\') c = 0xa5;
> > --
> > 2.30.2
> >
>
[-- Attachment #2: Type: text/html, Size: 2525 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] [PATCH] src: locale: fix potential NULL dereference in iconv() in
2025-02-17 15:50 ` Anton Moryakov
@ 2025-02-17 21:50 ` Thorsten Glaser
2025-02-17 23:17 ` Rich Felker
1 sibling, 0 replies; 5+ messages in thread
From: Thorsten Glaser @ 2025-02-17 21:50 UTC (permalink / raw)
To: musl
This…
>Thanks for the feedback!
… and no response to…
>> Why is the check necessary? I cannot find out a valid use case that the
>> scd pointer is NULL when converting from ISO2022_JP.
>>
>> Please have a look at iconv_open().
… as a general pattern for these mails makes me wonder whether
someone isn’t using the mailing list as a way to train their
static analyser tool…
bye,
//mirabilos
--
"Using Lynx is like wearing a really good pair of shades: cuts out
the glare and harmful UV (ultra-vanity), and you feel so-o-o COOL."
-- Henry Nelson, March 1999
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [musl] [PATCH] src: locale: fix potential NULL dereference in iconv() in
2025-02-17 15:50 ` Anton Moryakov
2025-02-17 21:50 ` Thorsten Glaser
@ 2025-02-17 23:17 ` Rich Felker
1 sibling, 0 replies; 5+ messages in thread
From: Rich Felker @ 2025-02-17 23:17 UTC (permalink / raw)
To: Anton Moryakov; +Cc: Yao Zi, musl
On Mon, Feb 17, 2025 at 06:50:48PM +0300, Anton Moryakov wrote:
> Thanks for the feedback!
>
> пн, 17 февр. 2025 г. в 18:38, Yao Zi <ziyao@disroot.org>:
>
> > On Mon, Feb 17, 2025 at 06:18:18PM +0300, Anton Moryakov wrote:
> > > Fixed a potential NULL dereference in iconv() by adding a check before
> > > accessing scd->state. If scd remains NULL due to cd & 1 != 0,
> > > dereferencing scd->state would cause undefined behavior.
> > >
> > > Previous code:
> > > switch (scd->state) { // Potential NULL dereference
> > >
> > > Fixed code:
> > > if (scd == NULL)
> > > goto ilseq;
> > > switch (scd->state) {
> > >
> > > This ensures that scd is properly validated before usage, preventing
> > crashes.
> > > Although the situation where scd == NULL is unlikely, I would recommend
> > adding this check
> >
> > Why is the check necessary? I cannot find out a valid use case that the
> > scd pointer is NULL when converting from ISO2022_JP.
> >
> > Please have a look at iconv_open().
Indeed, ISO2022_JP is the primary motivation for the existence of scd
and necessarily has scd!=0. If this invariant somehow weren't met due
to a bug, faulting on the access is the desired outcome. Treating a
violation of the invariant as an illegal input sequence error is
completely the wrong thing to do.
> > > Triggers found by static analyzer Svace.
From the results so far, it sounds like this is a very poor tool.
Is it suggesting the changes and change descriptions you're sending?
If not, is there another tool layered on top of it you're using that's
generating them according to some LLM, or are you writing them
yourself?
Rich
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-17 23:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-17 15:18 [musl] [PATCH] src: locale: fix potential NULL dereference in iconv() in Anton Moryakov
2025-02-17 15:37 ` Yao Zi
2025-02-17 15:50 ` Anton Moryakov
2025-02-17 21:50 ` Thorsten Glaser
2025-02-17 23:17 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).