alpine 3.9
format weakness #16

4

Weakness Breakdown


Definition:

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:

librsync/src/librsync-2.0.2/src/trace.h

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.9 format weakness.

  * error is always on, but you can return and continue in some way.
 *
 * fatal terminates the whole process.
 *
 * \todo A function like perror that includes strerror output. Apache does this
 * by adding flags as well as the severity level which say whether such
 * information should be included. */

#include <inttypes.h>
/* Printf format patters for standard librsync types. */
#define FMT_LONG "%"PRIdMAX
#define FMT_WEAKSUM "%08"PRIx32
/* Old MSVC compilers don't support "%zu" and have "%Iu" instead. */
#ifdef HAVE_PRINTF_Z
#  define FMT_SIZE "%zu"
#else
#  define FMT_SIZE "%Iu"
#endif

#if defined(__clang__) || defined(__GNUC__)
/** \todo Also look for the C9X predefined identifier '_function', or whatever
 * it's called. */

void rs_log0(int level, char const *fn, char const *fmt, ...)
    __attribute__ ((format(printf, 3, 4)));

#  ifdef DO_RS_TRACE
#    define rs_trace(fmt, arg...) \
    do { rs_log0(RS_LOG_DEBUG, __FUNCTION__, fmt , ##arg); \
    } while (0)
#  else
#    define rs_trace(fmt, arg...)
#  endif                        /* !DO_RS_TRACE */

#  define rs_log(l, s, str...) do { \
     rs_log0((l), __FUNCTION__, (s) , ##str); \
     } while (0)

#  define rs_error(s, str...) do { \
     rs_log0(RS_LOG_ERR,  __FUNCTION__, (s) , ##str); \
     } while (0)

#  define rs_fatal(s, str...) do { \
     rs_log0(RS_LOG_CRIT,  __FUNCTION__, \
	      (s) , ##str); \
     abort(); \
     } while (0)

#else                           /* !__GNUC__ */
#  define rs_trace rs_trace0 

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.