centos 6
format weakness #38


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.

File Name:



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

#include "file.h"

#ifndef lint
FILE_RCSID("@(#)$ File: print.c,v 1.68 2009/11/18 23:35:14 christos Exp $ ")
#endif  /* lint */

#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>

#define SZOF(a)	(sizeof(a) / sizeof(a[0]))

protected void
file_mdump(struct magic *m)
	private const char optyp[] = { FILE_OPS };

	(void) fprintf(stderr, "[%u", m->lineno);
	(void) fprintf(stderr, ">>>>>>>> %u" + 8 - (m->cont_level & 7),

	if (m->flag & INDIR) {
		(void) fprintf(stderr, "(%s,",
			       /* Note: type is unsigned */
			       (m->in_type < file_nnames) ? 
					file_names[m->in_type] : "*bad*");
		if (m->in_op & FILE_OPINVERSE)
			(void) fputc('~', stderr);
		(void) fprintf(stderr, "%c%u),",
			       ((size_t)(m->in_op & FILE_OPS_MASK) <
			       SZOF(optyp)) ? 
					optyp[m->in_op & FILE_OPS_MASK] : '?',
	(void) fprintf(stderr, " %s%s", (m->flag & UNSIGNED) ? "u" : "",
		       /* Note: type is unsigned */
		       (m->type < file_nnames) ? file_names[m->type] : "*bad*");
	if (m->mask_op & FILE_OPINVERSE)
		(void) fputc('~', stderr);

	if (IS_STRING(m->type)) {
		if (m->str_flags) {
			(void) fputc('/', stderr);
			if (m->str_flags & STRING_COMPACT_WHITESPACE)  

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.