fedora 24
buffer weakness #26

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:

CoinUtils-2.10.11/src/CoinFileIO.cpp

Context:

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

   {
    readType_="plain";
    if (fileName!="stdin") {
      f_ = fopen (fileName.c_str (), "r");
      if (f_ == 0)
        throw CoinError ("Could not open file for reading!", 
                         "CoinPlainFileInput", 
                         "CoinPlainFileInput");
    } else {
      f_ = stdin;
    }
  }

  virtual ~CoinPlainFileInput ()
  {
    if (f_ != 0)
      fclose (f_);
  }

  virtual int read (void *buffer, int size)
  {
    return static_cast<int>(fread (buffer, 1, size, f_));
  }

  virtual char *gets (char *buffer, int size)
  {
    return fgets (buffer, size, f_);
  }

private:
  FILE *f_;
};

// ------ helper class supporting buffered gets -------

// This is a CoinFileInput class to handle cases, where the gets method
// is not easy to implement (i.e. bzlib has no equivalent to gets, and
// zlib's gzgets is extremely slow). It's subclasses only have to implement
// the readRaw method, while the read and gets methods are handled by this
// class using an internal buffer.
class CoinGetslessFileInput: public CoinFileInput
{
public:
  CoinGetslessFileInput (const std::string &fileName): 
    CoinFileInput (fileName), 
    dataBuffer_ (8*1024), 
    dataStart_ (&dataBuffer_[0]), 
    dataEnd_ (&dataBuffer_[0])
  {}
 

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.