sim: validate IMS private identity
PATCH v2 1/1 sim: validate IMS private identity
Make sure that IMS private identity is a valid UTF8 string before setting sim->impi field. Otherwise ofono may crash on dbus assert when SIM properties are reported via org.ofono.SimManager interface.
--- src/sim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/sim.c +2 -1
@@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int total_length, int record,return ; } - sim->impi =g_strndup ((const char *)data +2 , data[1 ]); +if (g_utf8_validate ((const char *)data +2 , data[1 ],NULL )) + sim->impi =g_strndup ((const char *)data +2 , data[1 ]); } static void discover_apps_cb(const struct ofono_error *error,
Hi Sergey,
Quoted 12 lines · Sergey Matyukevich
Make sure that IMS private identity is a valid UTF8 string before setting
sim->impifield. Otherwise ofono may crash on dbus assert when SIM properties are reported via org.ofono.SimManager interface.--- src/sim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)src/sim.c +0
-0
src/sim.c static void impi_read_cb(int ok, int total_length, int record, · line 1668
Quoted 6 lines
src/sim.c +2
-1@@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int total_length, int record,return ; } - sim->impi =g_strndup ((const char *)data +2 , data[1 ]); +if (g_utf8_validate ((const char *)data +2 , data[1 ],NULL )) + sim->impi =g_strndup ((const char *)data +2 , data[1 ]);
I assume this code path was tested with a file containing embedded NULs as that is the only way it would have worked.
glib docs [1] say:
"Note that g_utf8_validate() returns FALSE if max_len is positive and any of the max_len bytes are nul."
So I think the above logic would flag such a file as invalid, no?
Quoted 7 lines
src/sim.c +0
-0} static void discover_apps_cb(const struct ofono_error *error,_______________________________________________
ofono mailing list -- ofono(a)ofono.org
To unsubscribe send an email to ofono-leave(a)ofono.org
Regards,
-Denis
[1]
https://developer.gnome.org/glib/stable/glib-Unicode-Manipulation.html#g-utf8-validate
Quoted 21 lines
Quoted 12 lines
Make sure that IMS private identity is a valid UTF8 string before setting
sim->impifield. Otherwise ofono may crash on dbus assert when SIM properties are reported via org.ofono.SimManager interface.--- src/sim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)src/sim.c +0
-0src/sim.c static void impi_read_cb(int ok, int total_length, int record, · line 1667
Quoted 5 lines
src/sim.c +2
-1@@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int total_length, int record,return ; } - sim->impi =g_strndup ((const char *)data +2 , data[1 ]); +if (g_utf8_validate ((const char *)data +2 , data[1 ],NULL )) + sim->impi =g_strndup ((const char *)data +2 , data[1 ]);I assume this code path was tested with a file containing embedded NULs as that is the only way it would have worked.
Quoted 5 lines
glib docs [1] say:
"Note thatg_utf8_validate()returns FALSE ifmax_lenis positive and any of themax_lenbytes are nul."So I think the above logic would flag such a file as invalid, no?
No, I tested using modem with attached SIM/eSIM. TLV data object appears to be well-formed, but the contents is all padding 0xff bytes. Could you please clarify your concern ? I assume we can not rely on the content being properly null terminated string.
Regards,
Sergey
Hi Sergey,
Quoted 7 lines · Sergey Matyukevich
Quoted 7 lines
Quoted 7 lines
Make sure that IMS private identity is a valid UTF8 string before setting
sim->impifield. Otherwise ofono may crash on dbus assert when SIM properties are reported via org.ofono.SimManager interface.--- src/sim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
src/sim.c +0
-0@@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int total_length, int record,Quoted 8 lines
src/sim.c static void impi_read_cb(int ok, int total_length, int record, · line 1668
Quoted 5 lines
src/sim.c +2
-1return ; } - sim->impi =g_strndup ((const char *)data +2 , data[1 ]); +if (g_utf8_validate ((const char *)data +2 , data[1 ],NULL )) + sim->impi =g_strndup ((const char *)data +2 , data[1 ]);I assume this code path was tested with a file containing embedded NULs as that is the only way it would have worked.
Ignore the last part of the above sentence. What I'm trying to say is that:
We in theory have two possibilities:
1. file with a string 'foo', no null:0x80 0x03 'f' 'o' 'o'
2. file with a string 'foo' and null:0x80 0x04 'f' 'o' 'o'
I suspect the spec really wants 1, but maybe it can be interpreted that 2 is also a possibility?
The present logic should work for either of the above, but not what you have, i.e.:
0x80 0x03 0xff 0xff 0xff
Quoted 7 lines
Quoted 6 lines
glib docs [1] say:
"Note thatg_utf8_validate()returns FALSE ifmax_lenis positive and any of themax_lenbytes are nul."So I think the above logic would flag such a file as invalid, no?
...but g_utf8_validate as invoked in this patch would flag possibility 2 as invalid...
Quoted 5 lines
No, I tested using modem with attached SIM/eSIM. TLV data object appears to be well-formed, but the contents is all padding
0xffbytes. Could you please clarify your concern ? I assume we can not rely on the content being properly null terminated string.
Yeah, for the case you have this logic works just fine.
Regards,
-Denis
Hi Denis,
Quoted 43 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Make sure that IMS private identity is a valid UTF8 string before setting
sim->impifield. Otherwise ofono may crash on dbus assert when SIM properties are reported via org.ofono.SimManager interface.--- src/sim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
src/sim.c +0
-0@@ -1664,7 +1664,8 @@ static void impi_read_cb(int ok, int total_length, int record,Quoted 8 lines
src/sim.c static void impi_read_cb(int ok, int total_length, int record, · line 1668
Quoted 5 lines
src/sim.c +2
-1return ; } - sim->impi =g_strndup ((const char *)data +2 , data[1 ]); +if (g_utf8_validate ((const char *)data +2 , data[1 ],NULL )) + sim->impi =g_strndup ((const char *)data +2 , data[1 ]);I assume this code path was tested with a file containing embedded NULs as that is the only way it would have worked.
Ignore the last part of the above sentence. What I'm trying to say is that:
We in theory have two possibilities:
1. file with a string 'foo', no null:
0x800x03'f' 'o' 'o'2. file with a string 'foo' and null:
0x800x04'f' 'o' 'o'I suspect the spec really wants 1, but maybe it can be interpreted that 2 is also a possibility?
The present logic should work for either of the above, but not what you have, i.e.:
0x800x030xff0xff0xffQuoted 5 lines
Quoted 5 lines
glib docs [1] say:
"Note thatg_utf8_validate()returns FALSE ifmax_lenis positive and any of themax_lenbytes are nul."
Quoted 5 lines
Quoted 2 lines
Quoted 1 line
So I think the above logic would flag such a file as invalid, no?
...but
g_utf8_validateas invoked in this patch would flag possibility 2 as invalid...
True. Thanks for detailed clarification. Indeed, both cases needs to be supported. Let me double-check and come back with v3.
Regards,
Sergey