Take length of format width specifier into account for format string buffer
authorPanu Matilainen <Panu Matilainen pmatilai@redhat.com>
Wed, 17 Aug 2011 06:03:44 +0000 (09:03 +0300)
committerPanu Matilainen <Panu Matilainen pmatilai@redhat.com>
Wed, 17 Aug 2011 06:03:44 +0000 (09:03 +0300)
- Prevents buffer overflow in case of ridiculous field width specifiers
  like --qf "%100000000000000000000000000{name}". There's another similar
  static-sized buffer in rpmtdFormat() but there we're not dealing
  with user-speficied format strings so its okay even if ugly.
- The format string handling wants a bigger overhaul but this makes
  for a nice little backportable patch for starters.

lib/headerfmt.c

index 45c52c2..86d2c1d 100644 (file)
@@ -618,7 +618,7 @@ static char * formatValue(headerSprintfArgs hsa, sprintfTag tag, int element)
     char * val = NULL;
     size_t need = 0;
     char * t, * te;
-    char buf[20];
+    char buf[strlen(tag->format) + 3]; /* extra for '%', fmt char and '\0' */
     rpmtd td;
 
     memset(buf, 0, sizeof(buf));