|
|
Message-Id: <20250217151818.830240-1-ant.v.moryakov@gmail.com>
Date: Mon, 17 Feb 2025 18:18:18 +0300
From: Anton Moryakov <ant.v.moryakov@...il.com>
To: musl@...ts.openwall.com
Cc: Anton Moryakov <ant.v.moryakov@...il.com>
Subject: [PATCH] src: locale: fix potential NULL dereference in iconv() in
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@...il.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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.