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
feature/tap-sh
A. Wilcox 2018-07-28 19:06:33 -05:00
parent 4735e17287
commit 9b7affe0b1
No known key found for this signature in database
GPG Key ID: CB29CB51922B9D14
1 changed files with 1 additions and 1 deletions

View File

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