diff mbox series

[1/6] stkagent: Use l_utf8_get_codepoint

Message ID 20240205213150.1001245-1-denkenz@gmail.com (mailing list archive)
State Accepted
Commit f5e6f0f6fddd5ab6a3d8d9ddff40177e9a73a375
Headers show
Series [1/6] stkagent: Use l_utf8_get_codepoint | expand

Commit Message

Denis Kenzior Feb. 5, 2024, 9:31 p.m. UTC
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(-)

Comments

patchwork-bot+ofono@kernel.org Feb. 6, 2024, 4:30 p.m. UTC | #1
Hello:

This series was applied to ofono.git (master)
by Denis Kenzior <denkenz@gmail.com>:

On Mon,  5 Feb 2024 15:31:22 -0600 you wrote:
> 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(-)

Here is the summary with links:
  - [1/6] stkagent: Use l_utf8_get_codepoint
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=f5e6f0f6fddd
  - [2/6] core: Remove g_utf8_strlen use
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=fdd0c0fca72b
  - [3/6] unit: Remove g_utf8_strlen use
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=c814b1f9b9b6
  - [4/6] qmimodem: Drop use of g_utf8_validate
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=39e2707386fd
  - [5/6] simutil: Drop use of g_utf8_validate_len
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=bce36de2f98e
  - [6/6] unit: Update to the new API
    https://git.kernel.org/pub/scm/network/ofono/ofono.git/?id=98a0809de309

You are awesome, thank you!
diff mbox series

Patch

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();