alpine 3.8
buffer weakness #36


Weakness Breakdown


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:



The highlighted line of code below is the trigger point of this particular Alpine 3.8 buffer weakness.

const char IOFile::READ[] = "rb";
const char IOFile::WRITE[] = "wb";
const char IOFile::APPEND[] = "ab";

IOFile::operator unspecified_bool_type() const
  bool ok = isOpen() && !isError();
  return ok ? &IOFile::goodState : nullptr;

size_t IOFile::read(void* ptr, size_t count) { return onRead(ptr, count); }

size_t IOFile::write(const void* ptr, size_t count)
  return onWrite(ptr, count);

size_t IOFile::write(const char* str) { return write(str, strlen(str)); }

char* IOFile::gets(char* s, int size) { return onGets(s, size); }

char* IOFile::getsn(char* s, int size)
  char* ptr = gets(s, size);
  if (ptr) {
    int len = strlen(ptr);
    if (ptr[len - 1] == '\n') {
      ptr[len - 1] = '\0';
  return ptr;

std::string IOFile::getLine()
  std::string res;
  if (eof()) {
    return res;
  std::array<char, 4_k> buf;
  while (gets(, buf.size())) {
    size_t len = strlen(;
    bool lineBreak = false;
    if (buf[len - 1] == '\n') {
      lineBreak = true;
    res.append(, len);
    if (lineBreak) { 

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.