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 738585 - [review] dcbw/keyfile-enum-flags: fix enum/flags types after libnm-core property changes
[review] dcbw/keyfile-enum-flags: fix enum/flags types after libnm-core prope...
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-10-15 16:06 UTC by Dan Williams
Modified: 2014-11-07 15:23 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Dan Williams 2014-10-15 16:06:32 UTC
When some properties got converted to G_TYPE_ENUM and G_TYPE_FLAGS
the keyfile plugin was not updated to handle these types.
Comment 1 Dan Winship 2014-10-15 16:37:30 UTC
Looks good. I was confused by this comment:

>+	/* Flags are 32-bit but GKeyFile only has uint64 functions */

until I realized you meant "doesn't have uint32 functions", not "has no 32-bit integer functions"
Comment 2 Thomas Haller 2014-10-15 20:36:23 UTC
+              if (uint_val <= G_MAXUINT32)
+                   g_object_set (setting, key, uint_val, NULL);

Are you sure that the maximum is G_MAXUINT32? I think it's G_MAXUINT.
I think, you also need a cast:
+                   g_object_set (setting, key, (guint) uint_val, NULL);


same later, just to make it explicit:
+              g_object_set (setting, key, (gint) int_val, NULL);


And I think, that glib still checks the integer value against the min/max values, and g_returns on out-of-range. Hence, invalid configurations can easily trigger a g_critical() by setting uint_val to a out-of-range value. But the same already applies to other integer types...



Interesting, that no existing tests caught this error...


Rest looks good to me.
Comment 3 Dan Williams 2014-10-17 00:17:40 UTC
(In reply to comment #2)
> +              if (uint_val <= G_MAXUINT32)
> +                   g_object_set (setting, key, uint_val, NULL);
> 
> Are you sure that the maximum is G_MAXUINT32? I think it's G_MAXUINT.
> I think, you also need a cast:
> +                   g_object_set (setting, key, (guint) uint_val, NULL);

Fixed.

> same later, just to make it explicit:
> +              g_object_set (setting, key, (gint) int_val, NULL);

Fixed.

> And I think, that glib still checks the integer value against the min/max
> values, and g_returns on out-of-range. Hence, invalid configurations can easily
> trigger a g_critical() by setting uint_val to a out-of-range value. But the
> same already applies to other integer types...

Yeah, it does:

g_enum_class_init():

      class->minimum = class->values->value;
      class->maximum = class->values->value;
      for (values = class->values; values->value_name; values++)
	{
	  class->minimum = MIN (class->minimum, values->value);
	  class->maximum = MAX (class->maximum, values->value);
	  class->n_values++;
	}

g_flags_class_init():

      for (values = class->values; values->value_name; values++)
	{
	  class->mask |= values->value;
	  class->n_values++;
	}

> Interesting, that no existing tests caught this error...

Yeah, we never tested the properties that would have triggered it.

Fixed the code comments per danw and merged to master.