fedora 25
format weakness #3

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):

Potential format string problem.

File Name:

GREYCstoration-2.8/src/CImg.h

Context:

The highlighted line of code below is the trigger point of this particular Fedora 25 format weakness.

                          const int x0, const int y0,
                         const CImg<tc>& fgcolor, const CImg<tc>& bgcolor,
                         const unsigned int font_size=11, const float opacity=1.0f) {
      const CImg<T> fgcol(fgcolor), bgcol(bgcolor);
      return draw_text(text,x0,y0,fgcol.data,bgcol.data,font_size,opacity);
    }

    //! Draw a text into the instance image.
    /**
       \param x0 X-coordinate of the text in the instance image.
       \param y0 Y-coordinate of the text in the instance image.
       \param fgcolor Array of dimv() values of type \c T, defining the foreground color (0 means 'transparent').
       \param bgcolor Array of dimv() values of type \c T, defining the background color (0 means 'transparent').
       \param font_size Size of the font (nearest match).
       \param opacity Drawing opacity.
       \param format 'printf'-style format string, followed by arguments.
       \note Clipping is supported.
    **/
    CImg<T>& draw_text(const int x0, const int y0,
                       const T *const fgcolor, const T *const bgcolor, const unsigned int font_size,
                       const float opacity, const char *format, ...) {
      char tmp[2048] = { 0 };
      std::va_list ap;
      va_start(ap,format);
      std::vsprintf(tmp,format,ap);
      va_end(ap);
      return draw_text(tmp,x0,y0,fgcolor,bgcolor,font_size,opacity);
    }

    template<typename tc>
      CImg<T>& draw_text(const int x0, const int y0,
                         const CImg<tc>& fgcolor, const CImg<tc>& bgcolor, const unsigned int font_size,
                         const float opacity, const char *format, ...) {
      char tmp[2048] = { 0 };
      std::va_list ap;
      va_start(ap,format);
      std::vsprintf(tmp,format,ap);
      va_end(ap);
      return draw_text(tmp,x0,y0,fgcolor,bgcolor,font_size,opacity);
    }

    //! Draw a text into the instance image.
    /**
       \param x0 X-coordinate of the text in the instance image.
       \param y0 Y-coordinate of the text in the instance image.
       \param fgcolor Array of dimv() values of type \c T, defining the foreground color (0 means 'transparent').
       \param bgcolor Array of dimv() values of type \c T, defining the background color (0 means 'transparent').
       \param font Font used for drawing text.
       \param opacity Drawing opacity.
       \param format 'printf'-style format string, followed by arguments. 

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.