* [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
* [PATCH 2/6] core: Remove g_utf8_strlen use
2024-02-05 21:31 [PATCH 1/6] stkagent: Use l_utf8_get_codepoint Denis Kenzior
@ 2024-02-05 21:31 ` Denis Kenzior
2024-02-05 21:31 ` [PATCH 3/6] unit: " Denis Kenzior
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2024-02-05 21:31 UTC (permalink / raw)
To: ofono; +Cc: Denis Kenzior
Replace with l_utf8_strlen
---
src/smsutil.c | 2 +-
src/stkagent.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/smsutil.c b/src/smsutil.c
index d07960190103..f46507f00e1c 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -549,7 +549,7 @@ gboolean sms_encode_address_field(const struct sms_address *in, gboolean sc,
unsigned char *r;
/* TP-OA's 10 octets transport 11 8-bit chars */
- if (g_utf8_strlen(addr, strlen(addr)) > 11)
+ if (l_utf8_strlen(addr) > 11)
return FALSE;
gsm = convert_utf8_to_gsm(in->address, len, NULL, &written, 0);
diff --git a/src/stkagent.c b/src/stkagent.c
index 6c1f6d57093f..8748ec63022c 100644
--- a/src/stkagent.c
+++ b/src/stkagent.c
@@ -838,7 +838,7 @@ static void get_input_cb(DBusPendingCall *call, void *data)
goto error;
}
- len = g_utf8_strlen(string, -1);
+ len = l_utf8_strlen(string);
if (len < agent->min_length || len > agent->max_length) {
ofono_error("Length not acceptable");
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] unit: Remove g_utf8_strlen use
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 ` Denis Kenzior
2024-02-05 21:31 ` [PATCH 4/6] qmimodem: Drop use of g_utf8_validate Denis Kenzior
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2024-02-05 21:31 UTC (permalink / raw)
To: ofono; +Cc: Denis Kenzior
Replace with l_utf8_strlen
---
unit/test-sms.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/unit/test-sms.c b/unit/test-sms.c
index 3bc099bcbdeb..154bb33ed244 100644
--- a/unit/test-sms.c
+++ b/unit/test-sms.c
@@ -1249,7 +1249,7 @@ static void test_prepare_concat(gconstpointer data)
sms_assembly_free(assembly);
}
-static void test_limit(gunichar uni, int target_size, gboolean use_16bit)
+static void test_limit(gunichar uni, size_t target_size, gboolean use_16bit)
{
char *utf8;
char *decoded;
@@ -1273,7 +1273,7 @@ static void test_limit(gunichar uni, int target_size, gboolean use_16bit)
g_assert(g_slist_length(l) == 255);
decoded = sms_decode_text(l);
- g_assert(g_utf8_strlen(decoded, -1) == target_size);
+ g_assert(l_utf8_strlen(decoded) == target_size);
g_free(decoded);
g_slist_free_full(l, g_free);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] qmimodem: Drop use of g_utf8_validate
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 ` Denis Kenzior
2024-02-05 21:31 ` [PATCH 5/6] simutil: Drop use of g_utf8_validate_len Denis Kenzior
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2024-02-05 21:31 UTC (permalink / raw)
To: ofono; +Cc: Denis Kenzior
Use l_utf8_validate instead.
---
drivers/qmimodem/network-registration.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/qmimodem/network-registration.c b/drivers/qmimodem/network-registration.c
index 3fa0c9e442fb..6bc8fbc5d226 100644
--- a/drivers/qmimodem/network-registration.c
+++ b/drivers/qmimodem/network-registration.c
@@ -32,6 +32,8 @@
#include <ofono/modem.h>
#include <ofono/netreg.h>
+#include <ell/ell.h>
+
#include "qmi.h"
#include "nas.h"
#include "util.h"
@@ -153,7 +155,7 @@ static bool extract_ss_info(struct qmi_result *result, int *status,
* plmn-desc. When that happens, libdbus will abort ofono.
* If non-utf-8 characters are detected, use mccmnc string.
*/
- if (g_utf8_validate(plmn->desc, opname_len, NULL)) {
+ if (l_utf8_validate(plmn->desc, opname_len, NULL)) {
strncpy(operator->name, plmn->desc, opname_len);
operator->name[opname_len] = '\0';
} else
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] simutil: Drop use of g_utf8_validate_len
2024-02-05 21:31 [PATCH 1/6] stkagent: Use l_utf8_get_codepoint Denis Kenzior
` (2 preceding siblings ...)
2024-02-05 21:31 ` [PATCH 4/6] qmimodem: Drop use of g_utf8_validate Denis Kenzior
@ 2024-02-05 21:31 ` 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
5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2024-02-05 21:31 UTC (permalink / raw)
To: ofono; +Cc: Denis Kenzior
Use l_utf8_validate instead.
---
src/simutil.c | 4 ++--
src/simutil.h | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/simutil.c b/src/simutil.c
index 59d8d5dd9c2d..0354cafd087f 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -766,7 +766,7 @@ unsigned char *comprehension_tlv_builder_get_data(
return tlv + tag_size + len_size;
}
-gboolean validate_utf8_tlv(const unsigned char *tlv)
+bool validate_utf8_tlv(const unsigned char *tlv)
{
int len = tlv[1];
@@ -777,7 +777,7 @@ gboolean validate_utf8_tlv(const unsigned char *tlv)
if (tlv[len + 1] == '\0')
len -= 1;
- return g_utf8_validate_len((const char *)tlv + 2, len, NULL);
+ return l_utf8_validate((const char *)tlv + 2, len, NULL);
}
static char *sim_network_name_parse(const unsigned char *buffer, int length,
diff --git a/src/simutil.h b/src/simutil.h
index f908bbb44d15..fd3967ffd336 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -19,6 +19,8 @@
*
*/
+#include <stdbool.h>
+
#define SIM_EFSPN_DC_HOME_PLMN_BIT 0x1
#define SIM_EFSPN_DC_ROAMING_SPN_BIT 0x2
@@ -408,7 +410,7 @@ gboolean comprehension_tlv_builder_set_length(
unsigned int len);
unsigned char *comprehension_tlv_builder_get_data(
struct comprehension_tlv_builder *builder);
-gboolean validate_utf8_tlv(const unsigned char *data);
+bool validate_utf8_tlv(const unsigned char *data);
void ber_tlv_iter_init(struct ber_tlv_iter *iter, const unsigned char *pdu,
unsigned int len);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] unit: Update to the new API
2024-02-05 21:31 [PATCH 1/6] stkagent: Use l_utf8_get_codepoint Denis Kenzior
` (3 preceding siblings ...)
2024-02-05 21:31 ` [PATCH 5/6] simutil: Drop use of g_utf8_validate_len Denis Kenzior
@ 2024-02-05 21:31 ` Denis Kenzior
2024-02-06 16:30 ` [PATCH 1/6] stkagent: Use l_utf8_get_codepoint patchwork-bot+ofono
5 siblings, 0 replies; 7+ messages in thread
From: Denis Kenzior @ 2024-02-05 21:31 UTC (permalink / raw)
To: ofono; +Cc: Denis Kenzior
The function now returns stdbool instead of gboolean, so update the use
accordingly and to the new coding style.
---
unit/test-simutil.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/unit/test-simutil.c b/unit/test-simutil.c
index 530f624e6b0b..8364f200c665 100644
--- a/unit/test-simutil.c
+++ b/unit/test-simutil.c
@@ -97,14 +97,14 @@ static void test_validate_tlv(void)
unsigned char impi_invalid1[] = { 0x80, 0x4, 'F', '\0', 'O', '\0' };
unsigned char impi_invalid2[] = { 0x80, 0x4, 0xff, 0xff, 0xff, 0xff };
- g_assert(validate_utf8_tlv(impi_none) == FALSE);
- g_assert(validate_utf8_tlv(impi_empty) == TRUE);
- g_assert(validate_utf8_tlv(impi_term1) == TRUE);
- g_assert(validate_utf8_tlv(impi_term2) == TRUE);
- g_assert(validate_utf8_tlv(impi_term3) == TRUE);
- g_assert(validate_utf8_tlv(impi_term4) == TRUE);
- g_assert(validate_utf8_tlv(impi_invalid1) == FALSE);
- g_assert(validate_utf8_tlv(impi_invalid2) == FALSE);
+ g_assert(!validate_utf8_tlv(impi_none));
+ g_assert(validate_utf8_tlv(impi_empty));
+ g_assert(validate_utf8_tlv(impi_term1));
+ g_assert(validate_utf8_tlv(impi_term2));
+ g_assert(validate_utf8_tlv(impi_term3));
+ g_assert(validate_utf8_tlv(impi_term4));
+ g_assert(!validate_utf8_tlv(impi_invalid1));
+ g_assert(!validate_utf8_tlv(impi_invalid2));
}
static void test_ber_tlv_builder_mms(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/6] stkagent: Use l_utf8_get_codepoint
2024-02-05 21:31 [PATCH 1/6] stkagent: Use l_utf8_get_codepoint Denis Kenzior
` (4 preceding siblings ...)
2024-02-05 21:31 ` [PATCH 6/6] unit: Update to the new API Denis Kenzior
@ 2024-02-06 16:30 ` patchwork-bot+ofono
5 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+ofono @ 2024-02-06 16:30 UTC (permalink / raw)
To: Denis Kenzior; +Cc: ofono
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [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.