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 780032 - Add missing attributes to two functions
Add missing attributes to two functions
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2017-03-14 12:57 UTC by Philip Withnall
Modified: 2017-03-22 11:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gdbusmessage: Add missing G_GNUC_PRINTF attribute (2.17 KB, patch)
2017-03-14 12:57 UTC, Philip Withnall
committed Details | Review
gsubprocess: Add missing G_GNUC_NULL_TERMINATED attribute (1.36 KB, patch)
2017-03-14 12:57 UTC, Philip Withnall
committed Details | Review

Description Philip Withnall 2017-03-14 12:57:30 UTC
Trivial patches attached.
Comment 1 Philip Withnall 2017-03-14 12:57:34 UTC
Created attachment 347917 [details] [review]
gdbusmessage: Add missing G_GNUC_PRINTF attribute

This highlighted a bug in GDBusConnection, where an interface name was
not included in a message referring to it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 2 Philip Withnall 2017-03-14 12:57:40 UTC
Created attachment 347918 [details] [review]
gsubprocess: Add missing G_GNUC_NULL_TERMINATED attribute

g_subprocess_launcher_spawn() is NULL-terminated, and must have a
non-NULL argv0 specified, so G_GNUC_NULL_TERMINATED is appropriate here.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 3 Philip Withnall 2017-03-14 12:58:35 UTC
Inspired by heftig on IRC.
Comment 4 Emmanuele Bassi (:ebassi) 2017-03-14 13:05:40 UTC
Review of attachment 347917 [details] [review]:

ACK.
Comment 5 Emmanuele Bassi (:ebassi) 2017-03-14 13:06:06 UTC
Review of attachment 347918 [details] [review]:

ACK.
Comment 6 Philip Withnall 2017-03-14 17:33:38 UTC
Attachment 347917 [details] pushed as ff327ba - gdbusmessage: Add missing G_GNUC_PRINTF attribute
Attachment 347918 [details] pushed as e1f362b - gsubprocess: Add missing G_GNUC_NULL_TERMINATED attribute
Comment 7 Rico Tzschichholz 2017-03-22 07:25:44 UTC
Using G_GNUC_PRINTF(3, 4) here is wrong and should be G_GNUC_PRINTF(3, 0)
Comment 8 Philip Withnall 2017-03-22 10:23:23 UTC
(In reply to Rico Tzschichholz from comment #7)
> Using G_GNUC_PRINTF(3, 4) here is wrong and should be G_GNUC_PRINTF(3, 0)

Why? The printf arguments are available to check in parameter 4.
Comment 9 Rico Tzschichholz 2017-03-22 10:46:05 UTC
My impression is that g_dbus_message_new_method_error can used with omitted variable argument-list, meaning to just pass a literal string without any format-args. I guess this is not the case here?

For reference this breaks the usage of g_dbus_message_new_method_error in networkmanager https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/nm-manager.c?h=nm-1-4#n4901
Comment 10 Philip Withnall 2017-03-22 10:56:58 UTC
G_GNUC_PRINTF(3, 4) should be fine for the case where the third argument doesn’t contain any format placeholders. It’s exactly the same as calling g_strdup_printf ("string with no placeholders").

What’s the warning message you get when compiling NetworkManager?
Comment 11 Rico Tzschichholz 2017-03-22 11:13:01 UTC
Its fails to build when using -Werror=format-security

nm-manager.c:4989:44: error: format not a string literal and no format arguments [-Werror=format-security]
                                            (error_message = "Not authorized to perform this operation"));
                                            ^
Comment 12 Emmanuele Bassi (:ebassi) 2017-03-22 11:37:54 UTC
This is the code:

https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/nm-manager.c#n5191

if (error || (result != NM_AUTH_CALL_RESULT_YES)) {
  reply = g_dbus_message_new_method_error (pfd->message,
                                           NM_PERM_DENIED_ERROR,
                                           (error_message = "Not authorized to perform this operation"));
  if (error)
    error_message = error->message;
  goto done;
}
Comment 13 Philip Withnall 2017-03-22 11:49:52 UTC
Looks to me like gcc is not clever enough to use the string literal from the assignment to error_message. I’d consider that a NetworkManager bug (or a bug in gcc). You can probably fix it as:

if (error || (result != NM_AUTH_CALL_RESULT_YES)) {
  reply = g_dbus_message_new_method_error (pfd->message,
                                           NM_PERM_DENIED_ERROR,
                                           "Not authorized to perform this operation");
  if (error)
    error_message = error->message;
  else
    g_variant_get (g_dbus_message_get_body (reply), "(&s)", &error_message);

  goto done;
}