~kaniini/pkgconf

Superfluous null bytes at the end of rendered buffers

Petr Pisar <ppisar@redhat.com>
Details
Message ID
<ZAn58pRMwbfkqaVF@dhcp-0-146.brq.redhat.com>
DKIM signature
missing
Download raw message
I observe a regression in pkgconf-1.9.4: pkgconf_fragment_render_len() returns
a byte more than necessary. As a result the buffer is stuffed with \0 bytes at
the end. That's a problem for language bindings which allow \0 bytes in
strings, like Perl. Those languages use pkgconf_fragment_render_len() - 1 to set
a length of a string to hold the buffer.

Attached is a reproducer. Here it's output:

$ gcc $(pkgconf --cflags libpkgconf) test.c $(pkgconf --libs libpkgconf)
$ ./a.out libpkgconf
buffer length = 24
string length = 22
-I/usr/include/pkgconf
[0]=0x2d (-)
[1]=0x49 (I)
[2]=0x2f (/)
[3]=0x75 (u)
[4]=0x73 (s)
[5]=0x72 (r)
[6]=0x2f (/)
[7]=0x69 (i)
[8]=0x6e (n)
[9]=0x63 (c)
[10]=0x6c (l)
[11]=0x75 (u)
[12]=0x64 (d)
[13]=0x65 (e)
[14]=0x2f (/)
[15]=0x70 (p)
[16]=0x6b (k)
[17]=0x67 (g)
[18]=0x63 (c)
[19]=0x6f (o)
[20]=0x6e (n)
[21]=0x66 (f)
[22]=0x00 ()
[23]=0x00 ()

I guess this is a fallout of 648a2249fcb10bf679bdb587ef2bbddaab3023ad commit
which removed the trailing space for cflags and libs.

Could you also please adjust the value returned from
pkgconf_fragment_render_len() to match the shortened strings?

-- Petr
Reply to thread Export thread (mbox)