stkagent: Use l_utf8_get_codepoint
PATCH 1/6 stkagent: Use l_utf8_get_codepoint
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(-)
src/stkagent.c +10 -2
@@ -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 ();
Signature · 1 line
2.43.0
PATCH 2/6 core: Remove g_utf8_strlen use
Replace with l_utf8_strlen
--- src/smsutil.c | 2 +- src/stkagent.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
src/smsutil.c +1 -1
@@ -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 );
src/stkagent.c +1 -1
@@ -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" );
Signature · 1 line
2.43.0
PATCH 3/6 unit: Remove g_utf8_strlen use
In reply to Denis KenziorReplace with l_utf8_strlen
--- unit/test-sms.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
unit/test-sms.c +2 -2
@@ -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);
Signature · 1 line
2.43.0
PATCH 4/6 qmimodem: Drop use of g_utf8_validate
In reply to Denis KenziorUse l_utf8_validate instead.
--- drivers/qmimodem/network-registration.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/qmimodem/network-registration.c +3 -1
@@ -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
Signature · 1 line
2.43.0
PATCH 5/6 simutil: Drop use of g_utf8_validate_len
In reply to Denis KenziorUse l_utf8_validate instead.
--- src/simutil.c | 4 ++-- src/simutil.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
src/simutil.c +2 -2
@@ -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,
src/simutil.h +3 -1
@@ -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);
Signature · 1 line
2.43.0
PATCH 6/6 unit: Update to the new API
In reply to Denis KenziorThe 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(-)
unit/test-simutil.c +8 -8
@@ -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 )
Signature · 1 line
2.43.0
This series was applied to ofono.git (master) by Denis Kenzior <[email protected]>:
Hello:
This series was applied to ofono.git (master)
by Denis Kenzior <[email protected]>:
Quoted 8 lines · 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 performsg_utf8_strlenwith a maximum size of 10 bytes in order to minimize unnecessary processing. Convert this code to use the more fittingl_utf8_get_codepointfunction, 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html