centos 6
format weakness #2


Weakness Breakdown


A format string exploit occurs when the data of an input string is evaluated as a command by the program. This class of attacks is very similar to buffer overflows since an attacker could execute code, read the stack or cause new behaviors that compromise security. Learn more about format string attacks on OWASP attack index.

Warning code(s):

If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always 0-terminate.

File Name:



The highlighted line of code below is the trigger point of this particular Centos 6 format weakness.

   TestStats *ts;
  ts = sr->stats;
  str = ck_strdup_printf ("%d%%: Checks: %d, Failures: %d, Errors: %d",
                          percent_passed (ts), ts->n_checked, ts->n_failed,

  return str;

char *ck_strdup_printf (const char *fmt, ...)
  /* Guess we need no more than 100 bytes. */
  int n, size = 100;
  char *p;
  va_list ap;

  p = emalloc (size);

  while (1)
      /* Try to print in the allocated space. */
      va_start(ap, fmt);
      n = vsnprintf (p, size, fmt, ap);
      /* If that worked, return the string. */
      if (n > -1 && n < size)
        return p;

      /* Else try again with more space. */
      if (n > -1)   /* C99 conform vsnprintf() */
        size = n+1; /* precisely what is needed */
      else          /* glibc 2.0 */
        size *= 2;  /* twice the old size */

      p = erealloc (p, size);

static const char *tr_type_str (TestResult *tr)
  const char *str = NULL;
  if (tr->ctx == CK_CTX_TEST) {
    if (tr->rtype == CK_PASS)
      str = "P";
    else if (tr->rtype == CK_FAILURE)
      str = "F";
    else if (tr->rtype == CK_ERROR)
      str = "E"; 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.