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 765338 - GLib.compute_hmac_for_data throws every time
GLib.compute_hmac_for_data throws every time
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-04-20 18:27 UTC by Andrea Giammarchi
Modified: 2016-07-17 00:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix annotations of g_compute_hmac_for_data (828 bytes, patch)
2016-04-20 18:49 UTC, Giovanni Campagna
committed Details | Review
Add g_compute_hmac_for_bytes() (2.45 KB, patch)
2016-04-20 18:49 UTC, Giovanni Campagna
committed Details | Review

Description Andrea Giammarchi 2016-04-20 18:27:34 UTC
Raised already in the GJS mailing list, which is why I am writing this here now, no matter how you invoke the following:

```
GLib.compute_hmac_for_data(
  GLib.ChecksumType.SHA1,
  'secret',
  'secret'.length,
  'the string',
  'the string'.length
);
```

it will always throw an error such `Segmentation fault (core dumped)` or something like `GLib-CRITICAL **: g_compute_hmac_for_data: assertion 'length == 0 || data != NULL' failed
null`

Hints about the issue? Giovanni Campagna guessed:

```
there seems to be an
annotation problem: argument data should be marked (array
length=length).
Right now for some reason it's inferred as guint8 (ie, the pointer is
lost), which is very wrong.
```
Comment 1 Giovanni Campagna 2016-04-20 18:49:11 UTC
Created attachment 326439 [details] [review]
Fix annotations of g_compute_hmac_for_data
Comment 2 Giovanni Campagna 2016-04-20 18:49:14 UTC
Created attachment 326440 [details] [review]
Add g_compute_hmac_for_bytes()

As an introspection-friendly GBytes variant of g_compute_hmac_for_data()
Comment 3 Colin Walters 2016-04-21 17:13:12 UTC
Review of attachment 326439 [details] [review]:

LGTM
Comment 4 Colin Walters 2016-04-21 17:16:08 UTC
Review of attachment 326440 [details] [review]:

Would be nice to have a test case even if it's trivial, just for the coverage aspect.

LGTM otherwise.

::: glib/ghmac.c
@@ +386,3 @@
+ *   The returned string should be freed with g_free() when done using it.
+ *
+ * Since: 2.30

2.50

::: glib/ghmac.h
@@ +74,3 @@
                                                      gssize         length);
 
+GLIB_AVAILABLE_IN_2_48

2.50 now I think.  Which we need to add.
Comment 5 Matthias Clasen 2016-07-17 00:48:54 UTC
Attachment 326439 [details] pushed as a9e9bc7 - Fix annotations of g_compute_hmac_for_data
Attachment 326440 [details] pushed as 183ed8a - Add g_compute_hmac_for_bytes()