All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] stkagent: Use l_utf8_get_codepoint
@ 2024-02-05 21:31 Denis Kenzior
  2024-02-05 21:31 ` [PATCH 2/6] core: Remove g_utf8_strlen use Denis Kenzior
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Denis Kenzior @ 2024-02-05 21:31 UTC (permalink / raw)
  To: ofono; +Cc: Denis Kenzior

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-06 16:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-05 21:31 [PATCH 1/6] stkagent: Use l_utf8_get_codepoint Denis Kenzior
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.