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 686838 - gtk_enumerate_printers() hangs
gtk_enumerate_printers() hangs
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Printing
3.15.x
Other Linux
: Normal major
: ---
Assigned To: gtk-bugs
gtk-bugs
: 605743 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-10-25 04:50 UTC by Evangelos Foutras
Modified: 2017-03-23 12:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Minimal test case; compile with: gcc -o list_printers $(pkg-config --cflags --libs gtk+-2.0 gtk+-unix-print-2.0) list_printers.c (401 bytes, text/x-csrc)
2012-10-25 04:50 UTC, Evangelos Foutras
  Details
Don't hang in gtk_enumerate_printers() (1.51 KB, patch)
2014-03-26 11:51 UTC, Marek Kašík
committed Details | Review

Description Evangelos Foutras 2012-10-25 04:50:42 UTC
Created attachment 227221 [details]
Minimal test case; compile with: gcc -o list_printers $(pkg-config --cflags --libs gtk+-2.0 gtk+-unix-print-2.0) list_printers.c

If CUPS isn't running, Chromium's call to gtk_enumerate_printers() will hang. This occurs with GTK+ >=2.24.11, and I'm guessing GTK+ >=3.4 is affected as well.

Commit 9a0e81380bfdc0abebbfa657abc974afeea6027b [1] has introduced this behavior; it was meant to address bug 672125 [2].

I have attached a minimal test case, which is a trimmed down version of the test case found on bug 668863 [3].

[1] http://git.gnome.org/browse/gtk+/commit/?h=gtk-2-24&id=9a0e81380bfdc0abebbfa657abc974afeea6027b
[2] https://bugzilla.gnome.org/show_bug.cgi?id=672125
[3] https://bugzilla.gnome.org/show_bug.cgi?id=668863
Comment 1 Evangelos Foutras 2012-10-25 05:23:50 UTC
I think I see what's happening:

1) list_printers_remove_backend() gets called to remove the CUPS backend since it's unavailable
2) printer_list->backends is now empty (NULL) so free_printer_list(printer_list) gets called
3) free_printer_list() does: g_free (printer_list)
4) control is returned to gtk_enumerate_printers() which checks: if (wait && printer_list->backends)
5) printer_list->backends is junk data (not NULL) so it proceeds to start the loop (and hangs here)

At least that's what I gathered with the help of GDB.
Comment 2 Evangelos Foutras 2012-12-22 18:00:07 UTC
@Carlos Garcia Campos:

Sorry I added you to the CC list. I hoped you might be able to help with this issue or maybe know someone who could.

Thanks.
Comment 3 Daniel Preston 2013-02-26 09:36:39 UTC
Is there any progress on this issue?
Comment 4 Marek Kašík 2014-03-26 11:51:55 UTC
Created attachment 272985 [details] [review]
Don't hang in gtk_enumerate_printers()

Hi,

thank you for the report. The gtk_enumerate_printer() function access already freed pointer as you wrote. The attached patch fixes this for me.

Regards

Marek
Comment 5 Morten Welinder 2015-03-13 13:55:04 UTC
*** Bug 605743 has been marked as a duplicate of this bug. ***
Comment 6 Morten Welinder 2015-03-13 13:59:41 UTC
Visual inspection of HEAD shows that the problem persists.
Patch applies cleanly although I am not in a position to actually test.
Comment 7 Evangelos Foutras 2015-03-13 15:36:57 UTC
The issue still exists in Gtk+ versions 2.24.27 and 3.14.9.

Note that I had to build Gtk+ 3.14.9 with --disable-cloudprint in order to reproduce the hang.

The patch by Marek seems to fix the issue with both Gtk+ versions I mentioned above.
Comment 8 Carlos Garcia Campos 2016-07-01 06:01:40 UTC
Review of attachment 272985 [details] [review]:

The patch is good, we need to ensure we don't run the inner loop when all backends have been removed and the printer list has been destroyed. There's indeed a user after free there, I'm surprised it doesn't crash.
Comment 9 Markus Keller 2016-10-20 13:00:11 UTC
This also caused many bug reports against SWT / Eclipse, see https://bugs.eclipse.org/215234
Comment 10 Matthias Clasen 2017-03-23 12:16:54 UTC
Review of attachment 272985 [details] [review]:

ok. Sorry for letting this languish for so long.
Comment 11 Marek Kašík 2017-03-23 12:22:10 UTC
Comment on attachment 272985 [details] [review]
Don't hang in gtk_enumerate_printers()

Thank you for the review. I've pushed the patch to gtk-3-22 and master branches.