Bug 3006 - infinite loop in "pkg-config --libs" with repeated package names
Summary: infinite loop in "pkg-config --libs" with repeated package names
Status: RESOLVED FIXED
Alias: None
Product: pkg-config
Classification: Unclassified
Component: src (show other bugs)
Version: unspecified
Hardware: x86 (IA32) Linux (All)
: high critical
Assignee: Tollef Fog Heen
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-13 01:37 UTC by James Henstridge
Modified: 2005-04-13 09:07 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
pkg-config-0.17.1-dupnames.patch (802 bytes, patch)
2005-04-13 18:11 UTC, James Henstridge
Details | Splinter Review

Description James Henstridge 2005-04-13 01:37:34 UTC
pkg-config-0.17.1 goes into an infinite loop when the "--libs" option when
configuring some packages (I've noticed it in gnome-media and epiphany so far --
there are probably some others).

It seems to be related to repeated package names in the argument list.  Here is
the simplest test case I could come up with:
  pkg-config --libs glib-2.0 glib-2.0

I guess this has something to do with the new libs list pruning you do, since
the following doesn't go into an infinite loop:
  pkg-config --libs --static glib-2.0 glib-2.0

The repeated package names don't need to be adjacent in the argument list.

Removing the duplicate package name in the argument list has worked around the
problem in each case I've found.

Unlike the M4 problems, this problem is going to affect people building source
tarballs.
Comment 1 James Henstridge 2005-04-13 18:11:12 UTC
Created attachment 2419 [details] [review]
pkg-config-0.17.1-dupnames.patch

Here's a patch that fixes the problem.	When packages_get_l_libs() is building
dups_list, it concatenates the result of get_l_libs() for each listed package.

Now get_l_libs() returns one of the members of the Package structure, and
shouldn't be modified.	But by concatenating those lists, you end up with a
cycle in the linked list.

Then when string_list_strip_duplicates_from_back() tries to simplify the list,
it has trouble when it tries to copy what seems to be an infinitely long linked
list.

Furthermore, if string_list_strip_duplicates_from_back() completes, when you
free dups_list you'd leave invalid pointers in the various Package structures.

packages_get_L_libs() has an equivalent problem, which the patch fixes in the
same way.
Comment 2 Tollef Fog Heen 2005-04-14 02:07:30 UTC
2005-04-13  Tollef Fog Heen  <tfheen@err.no>

	* pkg.c (packages_get_l_libs, packages_get_L_libs): Duplicate
	singly linked list before putting it on list passed to
	string_list_strip_duplicates_from_back to avoid infinite loop when
	g_slist_copy tries to copy self-linked list.  This happens if the
	user specifies the same name on the command line twice.
	(Freedesktop #3006)


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.