[glib: 8/17] gkeyfile: Move allocation of value until after error checking
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 8/17] gkeyfile: Move allocation of value until after error checking
- Date: Tue, 2 Nov 2021 11:08:16 +0000 (UTC)
commit cdcc06bbc58818e788365358ef46dd692bd09ba2
Author: Philip Withnall <pwithnall endlessos org>
Date: Sun Mar 14 14:09:34 2021 +0000
gkeyfile: Move allocation of value until after error checking
This doesn’t affect performance in the normal case of a valid key file,
but does improve performance when handling largely-invalid key files.
oss-fuzz#31796
Signed-off-by: Philip Withnall <pwithnall endlessos org>
glib/gkeyfile.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index 761a4141f..2e49b21f3 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -1398,8 +1398,6 @@ g_key_file_parse_key_value_pair (GKeyFile *key_file,
value_len = line + length - value_start;
- value = g_strndup (value_start, value_len);
-
g_warn_if_fail (key_file->start_group != NULL);
if (key_file->current_group
@@ -1407,9 +1405,10 @@ g_key_file_parse_key_value_pair (GKeyFile *key_file,
&& key_file->start_group == key_file->current_group
&& strcmp (key, "Encoding") == 0)
{
- if (g_ascii_strcasecmp (value, "UTF-8") != 0)
+ if (value_len != strlen ("UTF-8") ||
+ g_ascii_strncasecmp (value_start, "UTF-8", value_len) != 0)
{
- gchar *value_utf8 = g_utf8_make_valid (value, value_len);
+ gchar *value_utf8 = g_utf8_make_valid (value_start, value_len);
g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_UNKNOWN_ENCODING,
_("Key file contains unsupported "
@@ -1417,11 +1416,12 @@ g_key_file_parse_key_value_pair (GKeyFile *key_file,
g_free (value_utf8);
g_free (key);
- g_free (value);
return;
}
}
+ value = g_strndup (value_start, value_len);
+
/* Is this key a translation? If so, is it one that we care about?
*/
locale = key_get_locale (key);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]