Move file is regular check to load_from_file to use fstat() instead of

2004-10-27  Ray Strode  <rstrode@redhat.com>

	* glib/gkeyfile.c:
	 (g_key_file_load_from_fd),
	 (g_key_file_load_from_file):
	 Move file is regular check to load_from_file to use
	 fstat() instead of race prone g_file_test().  Don't
	 clear/init until needed. Change error messages to be
	 more consistent.
	 (g_key_file_load_from_data),
	 (g_key_file_load_from_data_dirs),
	 (g_key_file_parse_data),
	 (g_key_file_get_value),
	 (g_key_file_get_string),
	 (g_key_file_set_string),
	 (g_key_file_get_string_list),
	 (g_key_file_set_string_list),
	 (g_key_file_set_locale_string),
	 (g_key_file_get_locale_string),
	 (g_key_file_set_locale_string_list),
	 (g_key_file_get_boolean),
	 (g_key_file_set_boolean),
	 (g_key_file_get_boolean_list),
	 (g_key_file_set_boolean_list),
	 (g_key_file_get_integer),
	 (g_key_file_get_integer_list),
	 (g_key_file_set_integer_list),
	 (g_key_file_remove_key):
	 Add more g_return_*if_fail checks for public functions.
This commit is contained in:
Ray Strode 2004-10-27 21:22:01 +00:00 committed by Ray Strode
parent 24c2d623b5
commit 31c3bd53a2
6 changed files with 222 additions and 22 deletions

View File

@ -1,3 +1,33 @@
2004-10-27 Ray Strode <rstrode@redhat.com>
* glib/gkeyfile.c:
(g_key_file_load_from_fd),
(g_key_file_load_from_file):
Move file is regular check to load_from_file to use
fstat() instead of race prone g_file_test(). Don't
clear/init until needed. Change error messages to be
more consistent.
(g_key_file_load_from_data),
(g_key_file_load_from_data_dirs),
(g_key_file_parse_data),
(g_key_file_get_value),
(g_key_file_get_string),
(g_key_file_set_string),
(g_key_file_get_string_list),
(g_key_file_set_string_list),
(g_key_file_set_locale_string),
(g_key_file_get_locale_string),
(g_key_file_set_locale_string_list),
(g_key_file_get_boolean),
(g_key_file_set_boolean),
(g_key_file_get_boolean_list),
(g_key_file_set_boolean_list),
(g_key_file_get_integer),
(g_key_file_get_integer_list),
(g_key_file_set_integer_list),
(g_key_file_remove_key):
Add more g_return_*if_fail checks for public functions.
2004-10-27 Matthias Clasen <mclasen@redhat.com>
* configure.in: Bump version.

View File

@ -1,3 +1,33 @@
2004-10-27 Ray Strode <rstrode@redhat.com>
* glib/gkeyfile.c:
(g_key_file_load_from_fd),
(g_key_file_load_from_file):
Move file is regular check to load_from_file to use
fstat() instead of race prone g_file_test(). Don't
clear/init until needed. Change error messages to be
more consistent.
(g_key_file_load_from_data),
(g_key_file_load_from_data_dirs),
(g_key_file_parse_data),
(g_key_file_get_value),
(g_key_file_get_string),
(g_key_file_set_string),
(g_key_file_get_string_list),
(g_key_file_set_string_list),
(g_key_file_set_locale_string),
(g_key_file_get_locale_string),
(g_key_file_set_locale_string_list),
(g_key_file_get_boolean),
(g_key_file_set_boolean),
(g_key_file_get_boolean_list),
(g_key_file_set_boolean_list),
(g_key_file_get_integer),
(g_key_file_get_integer_list),
(g_key_file_set_integer_list),
(g_key_file_remove_key):
Add more g_return_*if_fail checks for public functions.
2004-10-27 Matthias Clasen <mclasen@redhat.com>
* configure.in: Bump version.

View File

@ -1,3 +1,33 @@
2004-10-27 Ray Strode <rstrode@redhat.com>
* glib/gkeyfile.c:
(g_key_file_load_from_fd),
(g_key_file_load_from_file):
Move file is regular check to load_from_file to use
fstat() instead of race prone g_file_test(). Don't
clear/init until needed. Change error messages to be
more consistent.
(g_key_file_load_from_data),
(g_key_file_load_from_data_dirs),
(g_key_file_parse_data),
(g_key_file_get_value),
(g_key_file_get_string),
(g_key_file_set_string),
(g_key_file_get_string_list),
(g_key_file_set_string_list),
(g_key_file_set_locale_string),
(g_key_file_get_locale_string),
(g_key_file_set_locale_string_list),
(g_key_file_get_boolean),
(g_key_file_set_boolean),
(g_key_file_get_boolean_list),
(g_key_file_set_boolean_list),
(g_key_file_get_integer),
(g_key_file_get_integer_list),
(g_key_file_set_integer_list),
(g_key_file_remove_key):
Add more g_return_*if_fail checks for public functions.
2004-10-27 Matthias Clasen <mclasen@redhat.com>
* configure.in: Bump version.

View File

@ -1,3 +1,33 @@
2004-10-27 Ray Strode <rstrode@redhat.com>
* glib/gkeyfile.c:
(g_key_file_load_from_fd),
(g_key_file_load_from_file):
Move file is regular check to load_from_file to use
fstat() instead of race prone g_file_test(). Don't
clear/init until needed. Change error messages to be
more consistent.
(g_key_file_load_from_data),
(g_key_file_load_from_data_dirs),
(g_key_file_parse_data),
(g_key_file_get_value),
(g_key_file_get_string),
(g_key_file_set_string),
(g_key_file_get_string_list),
(g_key_file_set_string_list),
(g_key_file_set_locale_string),
(g_key_file_get_locale_string),
(g_key_file_set_locale_string_list),
(g_key_file_get_boolean),
(g_key_file_set_boolean),
(g_key_file_get_boolean_list),
(g_key_file_set_boolean_list),
(g_key_file_get_integer),
(g_key_file_get_integer_list),
(g_key_file_set_integer_list),
(g_key_file_remove_key):
Add more g_return_*if_fail checks for public functions.
2004-10-27 Matthias Clasen <mclasen@redhat.com>
* configure.in: Bump version.

View File

@ -1,3 +1,33 @@
2004-10-27 Ray Strode <rstrode@redhat.com>
* glib/gkeyfile.c:
(g_key_file_load_from_fd),
(g_key_file_load_from_file):
Move file is regular check to load_from_file to use
fstat() instead of race prone g_file_test(). Don't
clear/init until needed. Change error messages to be
more consistent.
(g_key_file_load_from_data),
(g_key_file_load_from_data_dirs),
(g_key_file_parse_data),
(g_key_file_get_value),
(g_key_file_get_string),
(g_key_file_set_string),
(g_key_file_get_string_list),
(g_key_file_set_string_list),
(g_key_file_set_locale_string),
(g_key_file_get_locale_string),
(g_key_file_set_locale_string_list),
(g_key_file_get_boolean),
(g_key_file_set_boolean),
(g_key_file_get_boolean_list),
(g_key_file_set_boolean_list),
(g_key_file_get_integer),
(g_key_file_get_integer_list),
(g_key_file_set_integer_list),
(g_key_file_remove_key):
Add more g_return_*if_fail checks for public functions.
2004-10-27 Matthias Clasen <mclasen@redhat.com>
* configure.in: Bump version.

View File

@ -363,14 +363,15 @@ g_key_file_load_from_fd (GKeyFile *key_file,
struct stat stat_buf;
gchar read_buf[4096];
if (key_file->approximate_size > 0)
{
g_key_file_clear (key_file);
g_key_file_init (key_file);
}
key_file->flags = flags;
fstat (fd, &stat_buf);
if (!S_ISREG (stat_buf.st_mode))
{
g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_PARSE,
_("Not a regular file"));
return FALSE;
}
if (stat_buf.st_size == 0)
{
g_set_error (error, G_KEY_FILE_ERROR,
@ -379,6 +380,13 @@ g_key_file_load_from_fd (GKeyFile *key_file,
return FALSE;
}
if (key_file->approximate_size > 0)
{
g_key_file_clear (key_file);
g_key_file_init (key_file);
}
key_file->flags = flags;
bytes_read = 0;
do
{
@ -394,8 +402,7 @@ g_key_file_load_from_fd (GKeyFile *key_file,
g_set_error (error, G_FILE_ERROR,
g_file_error_from_errno (errno),
_("Failed to read from file: %s"),
g_strerror (errno));
"%s", g_strerror (errno));
return FALSE;
}
@ -448,23 +455,13 @@ g_key_file_load_from_file (GKeyFile *key_file,
g_return_val_if_fail (key_file != NULL, FALSE);
g_return_val_if_fail (file != NULL, FALSE);
if (!g_file_test (file, G_FILE_TEST_IS_REGULAR))
{
g_set_error (error, G_FILE_ERROR,
G_FILE_ERROR_ISDIR,
_("Failed to open file '%s': Not a regular file"),
file);
return FALSE;
}
fd = open (file, O_RDONLY);
if (fd < 0)
{
g_set_error (error, G_FILE_ERROR,
g_file_error_from_errno (errno),
_("Failed to open file '%s': %s"),
file, g_strerror (errno));
"%s", g_strerror (errno));
return FALSE;
}
@ -503,6 +500,7 @@ g_key_file_load_from_data (GKeyFile *key_file,
{
GError *key_file_error = NULL;
g_return_val_if_fail (key_file != NULL, FALSE);
g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (length != 0, FALSE);
@ -566,6 +564,7 @@ g_key_file_load_from_data_dirs (GKeyFile *key_file,
gint fd;
gboolean found_file;
g_return_val_if_fail (key_file != NULL, FALSE);
g_return_val_if_fail (!g_path_is_absolute (file), FALSE);
user_data_dir = g_get_user_data_dir ();
@ -843,6 +842,7 @@ g_key_file_parse_data (GKeyFile *key_file,
gsize i;
g_return_if_fail (key_file != NULL);
g_return_if_fail (data != NULL);
parse_error = NULL;
@ -1132,6 +1132,7 @@ g_key_file_get_value (GKeyFile *key_file,
g_return_val_if_fail (key_file != NULL, NULL);
g_return_val_if_fail (group_name != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
group = g_key_file_lookup_group (key_file, group_name);
@ -1221,6 +1222,7 @@ g_key_file_get_string (GKeyFile *key_file,
GError *key_file_error;
g_return_val_if_fail (key_file != NULL, NULL);
g_return_val_if_fail (group_name != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
key_file_error = NULL;
@ -1289,8 +1291,10 @@ g_key_file_set_string (GKeyFile *key_file,
gchar *value;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
g_return_if_fail (string != NULL);
value = g_key_file_parse_string_as_value (key_file, string, FALSE);
g_key_file_set_value (key_file, group_name, key, value);
g_free (value);
@ -1327,6 +1331,10 @@ g_key_file_get_string_list (GKeyFile *key_file,
gint i, len;
GSList *p, *pieces = NULL;
g_return_val_if_fail (key_file != NULL, NULL);
g_return_val_if_fail (group_name != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
value = g_key_file_get_value (key_file, group_name, key, &key_file_error);
if (key_file_error)
@ -1404,7 +1412,9 @@ g_key_file_set_string_list (GKeyFile *key_file,
gsize i;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
g_return_if_fail (list != NULL);
value_list = g_string_sized_new (length * 128);
for (i = 0; list[i] != NULL && i < length; i++)
@ -1446,7 +1456,10 @@ g_key_file_set_locale_string (GKeyFile *key_file,
gchar *full_key, *value;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
g_return_if_fail (locale != NULL);
g_return_if_fail (string != NULL);
value = g_key_file_parse_string_as_value (key_file, string, FALSE);
full_key = g_strdup_printf ("%s[%s]", key, locale);
@ -1494,6 +1507,10 @@ g_key_file_get_locale_string (GKeyFile *key_file,
gboolean free_languages = FALSE;
gint i;
g_return_val_if_fail (key_file != NULL, NULL);
g_return_val_if_fail (group_name != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
candidate_key = NULL;
translated_value = NULL;
key_file_error = NULL;
@ -1613,6 +1630,10 @@ g_key_file_get_locale_string_list (GKeyFile *key_file,
GError *key_file_error;
gchar **values, *value;
g_return_val_if_fail (key_file != NULL, NULL);
g_return_val_if_fail (group_name != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
key_file_error = NULL;
value = g_key_file_get_locale_string (key_file, group_name,
@ -1666,7 +1687,10 @@ g_key_file_set_locale_string_list (GKeyFile *key_file,
gsize i;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
g_return_if_fail (locale != NULL);
g_return_if_fail (length != 0);
value_list = g_string_sized_new (length * 128);
for (i = 0; list[i] != NULL && i < length; i++)
@ -1715,6 +1739,10 @@ g_key_file_get_boolean (GKeyFile *key_file,
gchar *value;
gboolean bool_value;
g_return_val_if_fail (key_file != NULL, FALSE);
g_return_val_if_fail (group_name != NULL, FALSE);
g_return_val_if_fail (key != NULL, FALSE);
value = g_key_file_get_value (key_file, group_name, key, &key_file_error);
if (!value)
@ -1768,6 +1796,7 @@ g_key_file_set_boolean (GKeyFile *key_file,
gchar *result;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
result = g_key_file_parse_boolean_as_value (key_file, value);
@ -1805,6 +1834,10 @@ g_key_file_get_boolean_list (GKeyFile *key_file,
gboolean *bool_values;
gsize i, num_bools;
g_return_val_if_fail (key_file != NULL, NULL);
g_return_val_if_fail (group_name != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
key_file_error = NULL;
values = g_key_file_get_string_list (key_file, group_name, key,
@ -1865,7 +1898,9 @@ g_key_file_set_boolean_list (GKeyFile *key_file,
gsize i;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
g_return_if_fail (list != NULL);
value_list = g_string_sized_new (length * 8);
for (i = 0; i < length; i++)
@ -1912,6 +1947,10 @@ g_key_file_get_integer (GKeyFile *key_file,
gchar *value;
gint int_value;
g_return_val_if_fail (key_file != NULL, -1);
g_return_val_if_fail (group_name != NULL, -1);
g_return_val_if_fail (key != NULL, -1);
key_file_error = NULL;
value = g_key_file_get_value (key_file, group_name, key, &key_file_error);
@ -1967,6 +2006,7 @@ g_key_file_set_integer (GKeyFile *key_file,
gchar *result;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
result = g_key_file_parse_integer_as_value (key_file, value);
@ -2005,6 +2045,10 @@ g_key_file_get_integer_list (GKeyFile *key_file,
gint *int_values;
gsize i, num_ints;
g_return_val_if_fail (key_file != NULL, NULL);
g_return_val_if_fail (group_name != NULL, NULL);
g_return_val_if_fail (key != NULL, NULL);
values = g_key_file_get_string_list (key_file, group_name, key,
&num_ints, &key_file_error);
@ -2063,7 +2107,9 @@ g_key_file_set_integer_list (GKeyFile *key_file,
gsize i;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
g_return_if_fail (list != NULL);
values = g_string_sized_new (length * 16);
for (i = 0; i < length; i++)
@ -2275,7 +2321,7 @@ g_key_file_get_key_comment (GKeyFile *key_file,
GList *key_node, *tmp;
GString *string;
gchar *comment;
group = g_key_file_lookup_group (key_file, group_name);
if (!group)
{
@ -2747,6 +2793,10 @@ g_key_file_remove_key (GKeyFile *key_file,
GKeyFileGroup *group;
GKeyFileKeyValuePair *pair;
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
g_return_if_fail (key != NULL);
pair = NULL;
if (group_name == NULL)