From: Denis Kenzior <denkenz@gmail.com>
To: ofono@lists.linux.dev
Cc: Denis Kenzior <denkenz@gmail.com>
Subject: [PATCH 1/6] stkagent: Use l_utf8_get_codepoint
Date: Mon, 5 Feb 2024 15:31:22 -0600 [thread overview]
Message-ID: <20240205213150.1001245-1-denkenz@gmail.com> (raw)
The GetKey() validation path ensures that the agent returns a single
UTF8 character. It performs g_utf8_strlen with a maximum size of 10
bytes in order to minimize unnecessary processing. Convert this code
to use the more fitting l_utf8_get_codepoint function, which will read
a single UTF8 character from the stream.
---
src/stkagent.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/stkagent.c b/src/stkagent.c
index a002fe9c716c..6c1f6d57093f 100644
--- a/src/stkagent.c
+++ b/src/stkagent.c
@@ -639,6 +639,8 @@ static void get_key_cb(DBusPendingCall *call, void *data)
enum stk_agent_result result;
bool remove_agent;
char *key;
+ int len;
+ wchar_t cp;
if (check_error(agent, reply,
ALLOWED_ERROR_GO_BACK | ALLOWED_ERROR_TERMINATE,
@@ -654,13 +656,19 @@ static void get_key_cb(DBusPendingCall *call, void *data)
if (dbus_message_get_args(reply, NULL,
DBUS_TYPE_STRING, &key,
- DBUS_TYPE_INVALID) == FALSE ||
- g_utf8_strlen(key, 10) != 1) {
+ DBUS_TYPE_INVALID) == FALSE) {
ofono_error("Can't parse the reply to GetKey()");
remove_agent = true;
goto error;
}
+ len = strlen(key);
+ if (l_utf8_get_codepoint(key, len, &cp) != len) {
+ ofono_error("GetKey() return expected a single character");
+ remove_agent = true;
+ goto error;
+ }
+
cb(result, key, agent->user_data);
CALLBACK_END();
--
2.43.0
next reply other threads:[~2024-02-05 21:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 21:31 Denis Kenzior [this message]
2024-02-05 21:31 ` [PATCH 2/6] core: Remove g_utf8_strlen use Denis Kenzior
2024-02-05 21:31 ` [PATCH 3/6] unit: " Denis Kenzior
2024-02-05 21:31 ` [PATCH 4/6] qmimodem: Drop use of g_utf8_validate Denis Kenzior
2024-02-05 21:31 ` [PATCH 5/6] simutil: Drop use of g_utf8_validate_len Denis Kenzior
2024-02-05 21:31 ` [PATCH 6/6] unit: Update to the new API Denis Kenzior
2024-02-06 16:30 ` [PATCH 1/6] stkagent: Use l_utf8_get_codepoint patchwork-bot+ofono
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=20240205213150.1001245-1-denkenz@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@lists.linux.dev \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).