VAITP Dataset

← Back to the dataset

CVE-2006-1542

Stack-based buffer overflow in Python < 2.4.2

  • CVSS 3.7
  • CWE-121: Stack-based Buffer Overflow
  • Memory Corruption
  • Local

Stack-based buffer overflow in Python 2.4.2 and earlier, running on Linux 2.6.12.5 under gcc 4.0.3 with libc 2.3.5, allows local users to cause a "stack overflow," and possibly gain privileges, by running a script from a current working directory that has a long name, related to the realpath function. NOTE: this might not be a vulnerability. However, the fact that it appears in a programming language interpreter could mean that some applications are affected, although attack scenarios might be limited because the attacker might already need to cross privilege boundaries to cause an exploitable program to be placed in a directory with a long name; or, depending on the method that Python uses to determine the current working directory, setuid applications might be affected.

CVSS base score
3.7
Published
2006-03-30
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Memory Corruption
Subcategory
Buffer Overflows
Accessibility scope
Local
Impact
Privilege Escalation
Fixed by upgrading
Yes

Solution

Upgrade to Python 2.4.3 or later.

Vulnerable code sample

import os

def realpath(path):
    resolved_path = os.path.realpath(path)
    return resolved_path

if __name__ == "__main__":
    long_directory_name = 'a' * 10000
    os.chdir(long_directory_name)
    user_input_path = input("Enter a path: ")
    resolved_path = realpath(user_input_path)
    print(f"Resolved path: {resolved_path}")

Patched code sample

import os

def realpath(path):
    try:
        resolved_path = os.path.realpath(path)
        if len(resolved_path) > 4096:
            raise ValueError("Resolved path is too long")
        return resolved_path
    except Exception as e:
        print(f"Error resolving path: {e}")
        return None

if __name__ == "__main__":
    user_input_path = input("Enter a path: ")
    path = realpath(user_input_path)
    if path:
        print(f"Resolved safe path: {path}")

Cite this entry

@misc{vaitp:cve20061542,
  title        = {{Stack-based buffer overflow in Python < 2.4.2}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2006},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2006-1542},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2006-1542/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::