alpine 3.6
buffer weakness #24

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

Easily used incorrectly.

File Name:

subversion/src/subversion-1.9.7/subversion/bindings/javahl/native/JNIStackElement.cpp

Context:

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

       static jmethodID mid = 0;
      if (mid == 0)
        {
          mid = env->GetMethodID(jlo, "toString", "()Ljava/lang/String;");
          if (JNIUtil::isJavaExceptionThrown())
            return;
        }

      *m_objectID = 0;

      if(jthis == NULL)
        {
          strcpy(m_objectID, "<static>");
        }
      else
        {
          // This will call java.lang.Object.toString, even when it is
          // overriden.
          jobject oStr = env->CallNonvirtualObjectMethod(jthis, jlo, mid);
          if (JNIUtil::isJavaExceptionThrown())
            return;

          // Copy the result to a buffer.
          JNIStringHolder name(reinterpret_cast<jstring>(oStr));
          strncat(m_objectID, name, sizeof(m_objectID) - 1);
          env->DeleteLocalRef(oStr);
        }

      // Release the Java string.
      env->DeleteLocalRef(jlo);

      // Remember the parameter for the exit of the method.
      m_clazz = clazz;
      m_method = method;

      // Generate the log message.
      char buffer[2048];
      apr_snprintf(buffer, sizeof(buffer),
                   "entry class %s method %s object %s", m_clazz, m_method,
                   m_objectID);
      JNIUtil::logMessage(buffer);
    }
  else
    {
      // Initialize the object cleanly.
      m_clazz = NULL;
      m_method = NULL;
      *m_objectID = 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.