After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 668756 - GKeyFile: allow loading from empty strings
GKeyFile: allow loading from empty strings
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-01-26 16:29 UTC by Allison Karlitskaya (desrt)
Modified: 2012-01-26 19:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GKeyFile: allow loading from empty strings (2.64 KB, patch)
2012-01-26 16:29 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Allison Karlitskaya (desrt) 2012-01-26 16:29:48 UTC
See patch.
Comment 1 Allison Karlitskaya (desrt) 2012-01-26 16:29:52 UTC
Created attachment 206200 [details] [review]
GKeyFile: allow loading from empty strings

GKeyFile supports empty files and also supports loading from the string
"", but will fail with a critical if you try:

  - explicit length == 0
  - data == NULL

length == 0 should always be valid, and data == NULL should be valid in
the case that length == 0, so add some testcases for those and fix the
code up to allow them.
Comment 2 Allison Karlitskaya (desrt) 2012-01-26 16:35:11 UTC
This problem can be seen if you do this:

  dconf dump /a/ | dconf load /b/

and /a/ is empty.

This pattern is a useful trick to migrate a bunch of keys.
Comment 3 Colin Walters 2012-01-26 17:12:46 UTC
Review of attachment 206200 [details] [review]:

::: glib/gkeyfile.c
@@ +890,2 @@
   if (length == (gsize)-1)
     length = strlen (data);

Hm, won't this segfault if length == 0 and data == NULL?
Comment 4 Allison Karlitskaya (desrt) 2012-01-26 19:02:41 UTC
NULL is a perfectly legitimate pointer to an array of length 0.  If the array has a length of zero then you are not entitled to do anything with the pointer anyway (because even reading the first element would already be past the end of the array).

Consider also that g_new() returns NULL if the number of requested elements is zero...
Comment 5 Colin Walters 2012-01-26 19:07:52 UTC
Review of attachment 206200 [details] [review]:

Nevermind, I misread the code.  Looks good.
Comment 6 Allison Karlitskaya (desrt) 2012-01-26 19:41:13 UTC
Attachment 206200 [details] pushed as 9bfde4a - GKeyFile: allow loading from empty strings