Browse Source

tuple: Ensure buf length is always >= 1 in dequote

If a key is defined with no value, dequote will allocate a buffer with a
length of 0.  Since the buffer's length is 0, any manipulation of its
content is UB.

Example .pc file:

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

xcflags=
xlibs= -lSM -lICE  -lX11

Name: Obt
Description: Openbox Toolkit Library
Version: 3.6
Requires: glib-2.0 libxml-2.0
Libs: -L${libdir} -lobt ${xlibs}
Cflags: -I${includedir}/openbox/3.6 ${xcflags}

Output using pkgconf 1.5.2 on x86_64 Linux/musl:

% pkgconf --cflags obt-3.5
-I/usr/include/openbox/3.6 \�\\�I\�\ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libxml2
A. Wilcox 3 months ago
parent
commit
9b7affe0b1
No known key found for this signature in database
1 changed files with 1 additions and 1 deletions
  1. 1
    1
      libpkgconf/tuple.c

+ 1
- 1
libpkgconf/tuple.c View File

@@ -139,7 +139,7 @@ pkgconf_tuple_find_delete(pkgconf_list_t *list, const char *key)
139 139
 static char *
140 140
 dequote(const char *value)
141 141
 {
142
-	char *buf = calloc(strlen(value) * 2, 1);
142
+	char *buf = calloc((strlen(value) + 1) * 2, 1);
143 143
 	char *bptr = buf;
144 144
 	const char *i;
145 145
 	char quote = 0;