fedora 25
buffer weakness #29

5

Weakness Breakdown


Definition:

Buffer overflows are one of the most well-known software vulnerabilities. Even though most developers know what buffer overflows are, attacks against the vulnerabilities are common in both legacy and newer applications. A classic buffer overflow exploit begins with the attacker sending data to a program, which it then stores in an undersized stack buffer. Besides stack buffer overflows, other kinds of buffer overflows include heap overflows, off-by-one errors and many others. Learn more about buffer overflows on OWASP attack index.

Warning code(s):

Does not check for buffer overflows.

File Name:

djvulibre-3.5.27/libdjvu/UnicodeByteStream.cpp

Context:

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

   if(len)
  {
    int i=buffer.search((char)stopat,bufferpos);
    if(i>=0)
    {
      if(inclusive)
      {
        ++i;
      }
      if(t&&(i>(int)t+bufferpos))
      {
        i=t+bufferpos;
      }
      if(i>bufferpos)
      {
        retval=buffer.substr(bufferpos,i-bufferpos);
      }
      bufferpos=i;
      linesread+=CountLines(retval);
    }else
    {
      retval=buffer.substr(bufferpos,len);
      bufferpos=buffer.length();
      linesread+=CountLines(retval);
      retval+=gets(t?(t-(i-bufferpos)):0,stopat,inclusive);
    }
  }
  return retval;
}

XMLByteStream::XMLByteStream(UnicodeByteStream &uni)
: UnicodeByteStream(uni) {}

XMLByteStream::XMLByteStream(GP<ByteStream> &ibs) 
: UnicodeByteStream(ibs,GStringRep::XOTHER)
{}

GP<XMLByteStream>
XMLByteStream::create(GP<ByteStream> ibs) 
{
  XMLByteStream *xml=new XMLByteStream(ibs);
  GP<XMLByteStream> retval=xml;
  xml->init();
  return retval;
}

void
XMLByteStream::init(void)
{
  unsigned char buf[4]; 

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.