Index | Thread | Search

From:
Theo Buehler <tb@theobuehler.org>
Subject:
pkgconf 3.0.11
To:
tech@openbsd.org
Date:
Tue, 17 Nov 2026 08:06:10 +0100

Download raw body.

Thread
  • Theo Buehler:

    pkgconf 3.0.11

Relevant for OpenBSD are these bits from the 3.0.11 NEWS:

* Security fixes:
  - Package paths are accepted only in queries made directly on the command
    line, not in Requires or Requires.private.  This prevents a crafted pc(5)
    file from causing infinite recursion by requiring itself through a path.
    See GHSA-qcp5-98c5-hvh7.
  - Limit the bytecode produced when a variable is repeatedly redefined in
    terms of itself.  This prevents a crafted pc(5) file from causing
    exponential memory growth through self-referential variable expansion.
    See GHSA-fr7f-m8jv-4qcm.

* Documentation and command-line help:
  - List the existing --debug and --license-file options in --help output.
    Patch by Andrej730.

https://github.com/pkgconf/pkgconf/blob/pkgconf-3.0.11/NEWS

There's a bit of regress to go with it (not included).

Index: cli/main.c
===================================================================
RCS file: /cvs/src/usr.bin/pkgconf/cli/main.c,v
diff -u -p -r1.4 main.c
--- cli/main.c	28 Aug 2026 09:06:01 -0000	1.4
+++ cli/main.c	17 Nov 2026 07:01:06 -0000
@@ -151,6 +151,7 @@ usage(void)
 	printf("  --print-errors                    ensure all errors are printed\n");
 	printf("  --short-errors                    be less verbose about some errors\n");
 	printf("  --silence-errors                  explicitly be silent about errors\n");
+	printf("  --debug                           print non-fatal warnings and debugging messages\n");
 	printf("  --list-all                        list all known packages\n");
 	printf("  --list-package-names              list all known package names\n");
 #ifndef PKGCONF_LITE
@@ -219,6 +220,7 @@ usage(void)
 	printf("  --modversion                      print the specified module's version to stdout\n");
 	printf("  --internal-cflags                 do not filter 'internal' cflags from output\n");
 	printf("  --license                         print the specified module's license to stdout if known\n");
+	printf("  --license-file                    print the specified module's license file location to stdout if known\n");
 	printf("  --link-abi                        print the link ABIs (e.g. c, c++) the module must be linked against\n");
 	printf("  --source                          print the specified module's source code location to stdout if known\n");
 	printf("  --exists-cflags                   add -DHAVE_FOO fragments to cflags for each found module\n");
Index: libpkgconf/bytecode.c
===================================================================
RCS file: /cvs/src/usr.bin/pkgconf/libpkgconf/bytecode.c,v
diff -u -p -r1.1 bytecode.c
--- libpkgconf/bytecode.c	7 Aug 2026 13:22:11 -0000	1.1
+++ libpkgconf/bytecode.c	17 Nov 2026 07:01:06 -0000
@@ -30,6 +30,7 @@
 
 #define PKGCONF_EVAL_MAX_OUTPUT (PKGCONF_BUFSIZE - 1)
 #define PKGCONF_EVAL_MAX_ITERATIONS (512)
+#define PKGCONF_BYTECODE_MAX_SPLICED_SIZE (PKGCONF_BUFSIZE)
 
 static bool
 pkgconf_bytecode_eval_append_slice(pkgconf_bytecode_eval_ctx_t *ctx, pkgconf_buffer_t *out, const char *p, size_t n)
@@ -517,10 +518,55 @@ pkgconf_bytecode_append_stream(pkgconf_b
 	return pkgconf_buffer_append_slice(dst, pkgconf_buffer_str(bcbuf), pkgconf_buffer_len(bcbuf));
 }
 
+/*
+ * Size of what pkgconf_bytecode_rewrite_selfrefs() would write, or false if
+ * `rhs` is malformed or the size passes PKGCONF_BYTECODE_MAX_SPLICED_SIZE.
+ *
+ * A self-reference is replaced by the whole of the previous definition, so a
+ * definition which names itself several times multiplies its own size, and a
+ * few such lines in a row would multiply it without limit.  Evaluation stops at
+ * PKGCONF_EVAL_MAX_OUTPUT whatever the bytecode says, so nothing useful lies
+ * past the limit, and this is checked before anything is allocated.
+ */
+static bool
+pkgconf_bytecode_spliced_size(const pkgconf_buffer_t *rhs, const char *key, const pkgconf_buffer_t *prev, size_t *size)
+{
+	const uint8_t *p = (const uint8_t *) rhs->base;
+	size_t remaining = pkgconf_buffer_len(rhs);
+	size_t prev_size = pkgconf_buffer_len(prev);
+	size_t total = *size;
+
+	while (remaining != 0)
+	{
+		const pkgconf_bytecode_op_t *op;
+		size_t op_size;
+
+		if (!pkgconf_bytecode_read_op(p, remaining, &op, &op_size))
+			return false;
+
+		size_t grow = pkgconf_bytecode_op_is_selfref(op, key) ? prev_size : op_size;
+
+		if (total > PKGCONF_BYTECODE_MAX_SPLICED_SIZE ||
+			grow > PKGCONF_BYTECODE_MAX_SPLICED_SIZE - total)
+			return false;
+
+		total += grow;
+		p += op_size;
+		remaining -= op_size;
+	}
+
+	*size = total;
+	return true;
+}
+
 bool
 pkgconf_bytecode_rewrite_selfrefs(pkgconf_buffer_t *out, const pkgconf_buffer_t *rhs, const char *key, const pkgconf_buffer_t *prev)
 {
 	if (out == NULL || rhs == NULL || key == NULL || prev == NULL)
+		return false;
+
+	size_t spliced_size = pkgconf_buffer_len(out);
+	if (!pkgconf_bytecode_spliced_size(rhs, key, prev, &spliced_size))
 		return false;
 
 	const uint8_t *p = (const uint8_t *) rhs->base;
Index: libpkgconf/config.h
===================================================================
RCS file: /cvs/src/usr.bin/pkgconf/libpkgconf/config.h,v
diff -u -p -r1.9 config.h
--- libpkgconf/config.h	19 Oct 2026 13:24:36 -0000	1.9
+++ libpkgconf/config.h	17 Nov 2026 07:01:06 -0000
@@ -1,6 +1,6 @@
 #define PACKAGE_NAME "pkgconf-lite"
 #define PACKAGE_BUGREPORT "https://github.com/pkgconf/pkgconf/issues"
-#define PACKAGE_VERSION "3.0.10"
+#define PACKAGE_VERSION "3.0.11"
 #define PACKAGE PACKAGE_NAME " " PACKAGE_VERSION
 
 #define HAVE_DECL_STRNDUP	1
Index: libpkgconf/libpkgconf.h
===================================================================
RCS file: /cvs/src/usr.bin/pkgconf/libpkgconf/libpkgconf.h,v
diff -u -p -r1.7 libpkgconf.h
--- libpkgconf/libpkgconf.h	19 Oct 2026 13:24:36 -0000	1.7
+++ libpkgconf/libpkgconf.h	17 Nov 2026 07:01:06 -0000
@@ -71,8 +71,8 @@ typedef struct pkgconf_license_ pkgconf_
 #define PKGCONF_FOREACH_LIST_ENTRY_REVERSE(tail, value) \
 	for ((value) = (tail); (value) != NULL; (value) = (value)->prev)
 
-#define LIBPKGCONF_VERSION	30010
-#define LIBPKGCONF_VERSION_STR	"3.0.10"
+#define LIBPKGCONF_VERSION	30011
+#define LIBPKGCONF_VERSION_STR	"3.0.11"
 
 struct pkgconf_queue_ {
 	pkgconf_node_t iter;
Index: libpkgconf/pkg.c
===================================================================
RCS file: /cvs/src/usr.bin/pkgconf/libpkgconf/pkg.c,v
diff -u -p -r1.4 pkg.c
--- libpkgconf/pkg.c	28 Aug 2026 09:06:01 -0000	1.4
+++ libpkgconf/pkg.c	17 Nov 2026 07:01:06 -0000
@@ -1135,28 +1135,38 @@ search_preload_list(pkgconf_client_t *cl
 	return NULL;
 }
 
+static inline bool
+name_has_path_separator(const char *name)
+{
+	for (; *name != '\0'; name++)
+		if (is_path_separator(*name))
+			return true;
+
+	return false;
+}
+
 /*
- * !doc
- *
- * .. c:function:: pkgconf_pkg_t *pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
- *
- *    Search for a package.
- *
- *    :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
- *    :param char* name: The name of the package `atom` to use for searching.
- *    :return: A package object reference if the package was found, else ``NULL``.
- *    :rtype: pkgconf_pkg_t *
+ * Only a name the user asked for may be a path.  A name which a .pc file
+ * supplies is a module name: letting it be a path would let the file reach
+ * outside the search path, and would let it spell one module several ways,
+ * each of which loads as a package the cache has never seen.
  */
-pkgconf_pkg_t *
-pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
+static pkgconf_pkg_t *
+pkg_find(pkgconf_client_t *client, const char *name, bool allow_path)
 {
 	pkgconf_pkg_t *pkg = NULL;
 	pkgconf_node_t *n;
 
 	PKGCONF_TRACE(client, "looking for: %s", name);
 
+	if (!allow_path && name_has_path_separator(name))
+	{
+		PKGCONF_TRACE(client, "%s is a path, which only a query may use", name);
+		return NULL;
+	}
+
 	/* name might actually be a filename. */
-	if (str_has_suffix(name, PKG_CONFIG_EXT))
+	if (allow_path && str_has_suffix(name, PKG_CONFIG_EXT))
 	{
 		pkg = pkgconf_pkg_new_from_path(client, name, 0);
 		if (pkg != NULL)
@@ -1200,6 +1210,24 @@ out:
 	return pkg;
 }
 
+/*
+ * !doc
+ *
+ * .. c:function:: pkgconf_pkg_t *pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
+ *
+ *    Search for a package.
+ *
+ *    :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
+ *    :param char* name: The name of the package `atom` to use for searching.
+ *    :return: A package object reference if the package was found, else ``NULL``.
+ *    :rtype: pkgconf_pkg_t *
+ */
+pkgconf_pkg_t *
+pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
+{
+	return pkg_find(client, name, true);
+}
+
 typedef bool (*pkgconf_vercmp_res_func_t)(const char *a, const char *b);
 
 typedef struct {
@@ -1533,7 +1561,7 @@ pkgconf_pkg_verify_dependency(pkgconf_cl
 		return pkgconf_pkg_ref(client, pkgdep->match);
 	}
 
-	pkg = pkgconf_pkg_find(client, pkgdep->package);
+	pkg = pkg_find(client, pkgdep->package, (pkgdep->flags & PKGCONF_PKG_DEPF_QUERY) != 0);
 	if (pkg == NULL)
 	{
 		if (client->flags & PKGCONF_PKG_PKGF_SKIP_PROVIDES)
Index: libpkgconf/tuple.c
===================================================================
RCS file: /cvs/src/usr.bin/pkgconf/libpkgconf/tuple.c,v
diff -u -p -r1.2 tuple.c
--- libpkgconf/tuple.c	7 Aug 2026 13:22:11 -0000	1.2
+++ libpkgconf/tuple.c	17 Nov 2026 07:01:06 -0000
@@ -179,8 +179,6 @@ pkgconf_tuple_add(const pkgconf_client_t
 	char *dequote_value;
 	pkgconf_buffer_t rhs_bcbuf = PKGCONF_BUFFER_INITIALIZER;
 
-	(void) client;
-
 	if (list == NULL || key == NULL || value == NULL)
 		return NULL;
 
@@ -235,6 +233,9 @@ pkgconf_tuple_add(const pkgconf_client_t
 		/* splice the selfrefs, using the old bytecode instead of ${var} */
 		if (!pkgconf_bytecode_rewrite_selfrefs(&new_bcbuf, &rhs_bcbuf, key, &old_bcbuf))
 		{
+			if (client != NULL)
+				pkgconf_warn(client, "warning: variable '%s' could not be redefined in terms of itself (the limit is 64KB), keeping its previous definition\n", key);
+
 			pkgconf_buffer_finalize(&old_bcbuf);
 			pkgconf_buffer_finalize(&new_bcbuf);
 			pkgconf_buffer_finalize(&rhs_bcbuf);