Fix memory allocation for token array
authorLubomir Rintel <lkundrak@v3.sk>
Mon, 22 Jun 2009 22:49:17 +0000 (00:49 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 14 Jul 2009 11:33:15 +0000 (14:33 +0300)
This fixes a memory corruption due to write access out of
bounds of token array, whose size was computed incorrectly.
It was assumed that only '%' characters separate tokens,
which could lead to crashes on useless uses of '[' tokens,
such as "rpm -qa --qf '[]lalala'".

lib/headerfmt.c

index 569bc0e..d395658 100644 (file)
@@ -296,7 +296,7 @@ static int parseFormat(headerSprintfArgs hsa, char * str,
     numTokens = 0;
     if (str != NULL)
     for (chptr = str; *chptr != '\0'; chptr++)
-       if (*chptr == '%') numTokens++;
+       if (*chptr == '%' || *chptr == '[') numTokens++;
     numTokens = numTokens * 2 + 1;
 
     format = xcalloc(numTokens, sizeof(*format));