Use of Obsolete Function

Description

Use of Obsolete Function is a vulnerability where code employs deprecated or outdated functions, indicating the codebase may lack active maintenance or security review. Programming languages evolve over time, causing functions to become obsolete due to language advancements, improved operational understanding and security practices, or shifted conventions governing specific operations. Deprecated functions are typically superseded by newer alternatives that accomplish the same task more effectively or securely.

Risk

Obsolete functions often have known security vulnerabilities or design flaws that led to their deprecation. Using gets() in C allows buffer overflow. Using strcpy() without length limits enables overflow attacks. Deprecated hash functions like MD5 or SHA1 have known weaknesses. Obsolete random number generators may be predictable. Code using deprecated functions signals poor maintenance practices and may contain other unpatched vulnerabilities. The presence of obsolete functions may indicate the codebase hasn't been reviewed against current security standards.

Solution

Review the obsolete function's documentation to understand the deprecation rationale and identify modern alternatives for achieving equivalent functionality. During requirements and implementation phases, evaluate security implications carefully and replace obsolete functions with modern alternatives. Use compiler warnings for deprecated functions (-Wdeprecated in GCC/Clang). Maintain a list of deprecated functions and check for them in code reviews. Update build systems to fail on use of known-dangerous deprecated functions.

Common Consequences

ImpactDetails
OtherScope: Other

Quality Degradation - Code using obsolete functions may have reduced security, reliability, or performance compared to code using modern alternatives.
OtherScope: Other

Indirect Security Impact - Obsolete functions may have known vulnerabilities or design flaws that create security weaknesses.

Example Code

Vulnerable Code

// Vulnerable: Using dangerous obsolete C functions
#include <stdio.h>
#include <string.h>
#include <crypt.h>

void vulnerable_gets_usage() {
    char buffer[100];

    // Vulnerable: gets() is obsolete and dangerous
    // No bounds checking - guaranteed buffer overflow risk
    // REMOVED from C11 standard
    gets(buffer);  // NEVER use this

    printf("Input: %s\n", buffer);
}

void vulnerable_strcpy_usage(const char *input) {
    char buffer[50];

    // Vulnerable: strcpy() has no length limit
    // Deprecated in favor of strncpy() or strlcpy()
    strcpy(buffer, input);

    // Vulnerable: sprintf() has no length limit
    // Deprecated in favor of snprintf()
    sprintf(buffer, "Value: %s", input);
}

void vulnerable_password_handling(const char *password) {
    // Vulnerable: crypt() with DES is obsolete
    // DES has only 56-bit keys and other weaknesses
    char *hash = crypt(password, "ab");  // Two-character DES salt

    // Vulnerable: getpw() is obsolete and dangerous
    // Buffer overflow risk, use getpwuid() instead
    char buffer[256];
    getpw(getuid(), buffer);
}

void vulnerable_random_generation() {
    // Vulnerable: rand() and srand() are obsolete for security use
    // Predictable, weak PRNG
    srand(time(NULL));
    int random_value = rand();

    // Vulnerable: random() is better but still not cryptographic
    srandom(time(NULL));
    long random_long = random();
}
// Vulnerable: Using deprecated Java APIs
import java.util.*;
import java.security.*;

public class VulnerableObsoleteJava {

    // Vulnerable: Using deprecated Date methods
    public Date vulnerableDateUsage() {
        Date date = new Date();

        // Deprecated: Use Calendar or java.time instead
        date.setYear(2024);   // Deprecated since JDK 1.1
        date.setMonth(11);    // Deprecated
        date.setDate(25);     // Deprecated

        return date;
    }

    // Vulnerable: Using deprecated Thread methods
    public void vulnerableThreadUsage(Thread thread) {
        // Deprecated: stop() is inherently unsafe
        // Can leave objects in inconsistent state
        thread.stop();  // Deprecated

        // Deprecated: suspend() and resume() are deadlock-prone
        thread.suspend();  // Deprecated
        thread.resume();   // Deprecated
    }

    // Vulnerable: Using deprecated String constructor
    public String vulnerableStringUsage(byte[] data) {
        // Deprecated: This constructor doesn't specify charset
        // Behavior depends on platform default encoding
        return new String(data, 0);  // Deprecated
    }

    // Vulnerable: Using weak cryptographic algorithms
    public void vulnerableCrypto() throws Exception {
        // Vulnerable: DES is obsolete, use AES
        Cipher cipher = Cipher.getInstance("DES");

        // Vulnerable: MD5 is broken for security purposes
        MessageDigest md5 = MessageDigest.getInstance("MD5");

        // Vulnerable: SHA1 is deprecated for signatures
        Signature sig = Signature.getInstance("SHA1withRSA");
    }
}
# Vulnerable: Using deprecated Python APIs
import os
import cgi
import crypt
import hashlib

# Vulnerable: os.popen() is deprecated
def vulnerable_command_execution(command):
    # Deprecated: Use subprocess module instead
    output = os.popen(command).read()  # Deprecated
    return output

# Vulnerable: cgi module is deprecated in Python 3.11+
def vulnerable_cgi_usage(data):
    # Deprecated: cgi module being phased out
    form = cgi.FieldStorage()  # Deprecated
    return form.getvalue('name')

# Vulnerable: Using weak hash functions
def vulnerable_password_hashing(password):
    # Deprecated: MD5 is cryptographically broken
    md5_hash = hashlib.md5(password.encode()).hexdigest()

    # Deprecated: SHA1 is weak for security purposes
    sha1_hash = hashlib.sha1(password.encode()).hexdigest()

    # Deprecated: crypt module uses weak DES by default
    hash_result = crypt.crypt(password)

    return md5_hash, sha1_hash, hash_result

# Vulnerable: Using deprecated formatting
def vulnerable_string_formatting(name, value):
    # Deprecated style (still works but discouraged)
    result = "Name: %s, Value: %d" % (name, value)
    return result

Fixed Code

// Fixed: Using modern, secure C functions
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/random.h>

void secure_input_handling() {
    char buffer[100];

    // Fixed: Use fgets() with explicit size limit
    if (fgets(buffer, sizeof(buffer), stdin) != NULL) {
        // Remove trailing newline
        size_t len = strlen(buffer);
        if (len > 0 && buffer[len-1] == '\n') {
            buffer[len-1] = '\0';
        }
    }

    printf("Input: %s\n", buffer);
}

void secure_string_copy(const char *input) {
    char buffer[50];

    // Fixed: Use snprintf() with explicit size limit
    snprintf(buffer, sizeof(buffer), "%s", input);

    // Fixed: Use strlcpy() where available
    // strlcpy(buffer, input, sizeof(buffer));

    // Fixed: Use snprintf() for formatted strings
    snprintf(buffer, sizeof(buffer), "Value: %s", input);
}

void secure_password_handling(const char *password) {
    // Fixed: Use modern password hashing
    // Option 1: crypt() with bcrypt (if available)
    char *hash = crypt(password, "$2b$12$.....................");

    // Option 2: Use libsodium or other modern library
    // crypto_pwhash_str(hash, password, strlen(password),
    //                   crypto_pwhash_OPSLIMIT_MODERATE,
    //                   crypto_pwhash_MEMLIMIT_MODERATE);

    // Fixed: Use getpwuid() instead of getpw()
    struct passwd *pw = getpwuid(getuid());
    if (pw != NULL) {
        // Use pw->pw_name, pw->pw_dir, etc.
    }
}

void secure_random_generation() {
    // Fixed: Use cryptographic random source
    unsigned char random_bytes[16];

    // Option 1: getrandom() on Linux
    getrandom(random_bytes, sizeof(random_bytes), 0);

    // Option 2: /dev/urandom
    FILE *f = fopen("/dev/urandom", "rb");
    if (f) {
        fread(random_bytes, 1, sizeof(random_bytes), f);
        fclose(f);
    }

    // Option 3: arc4random() on BSD/macOS
    // uint32_t random_value = arc4random();
}
// Fixed: Using modern Java APIs
import java.time.*;
import java.security.*;
import javax.crypto.*;

public class SecureModernJava {

    // Fixed: Using java.time API
    public LocalDate secureDate() {
        // Fixed: Use java.time classes (Java 8+)
        return LocalDate.of(2024, 12, 25);
    }

    // Fixed: Safe thread termination
    public void secureThreadTermination(Thread thread) {
        // Fixed: Use interrupt() and cooperative termination
        thread.interrupt();

        // Thread should check isInterrupted() and exit cleanly
    }

    // Fixed: Specify charset explicitly
    public String secureStringConversion(byte[] data) {
        // Fixed: Specify charset explicitly
        return new String(data, java.nio.charset.StandardCharsets.UTF_8);
    }

    // Fixed: Use modern cryptographic algorithms
    public void secureCrypto() throws Exception {
        // Fixed: Use AES instead of DES
        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");

        // Fixed: Use SHA-256 or SHA-3 instead of MD5
        MessageDigest sha256 = MessageDigest.getInstance("SHA-256");

        // Fixed: Use SHA-256 or better for signatures
        Signature sig = Signature.getInstance("SHA256withRSA");
    }
}
# Fixed: Using modern Python APIs
import subprocess
import hashlib
import secrets
import bcrypt  # or argon2-cffi

# Fixed: Use subprocess instead of os.popen
def secure_command_execution(command_args):
    # Fixed: Use subprocess with list of arguments
    # Avoid shell=True when possible
    result = subprocess.run(
        command_args,
        capture_output=True,
        text=True,
        check=True
    )
    return result.stdout

# Fixed: Use modern web frameworks instead of cgi
def secure_web_input():
    # Fixed: Use Flask, Django, or other modern framework
    # from flask import request
    # return request.form.get('name')
    pass

# Fixed: Use strong password hashing
def secure_password_hashing(password):
    # Fixed: Use bcrypt
    salt = bcrypt.gensalt(rounds=12)
    hash_result = bcrypt.hashpw(password.encode(), salt)

    # Or use Argon2 (recommended)
    # from argon2 import PasswordHasher
    # ph = PasswordHasher()
    # hash_result = ph.hash(password)

    return hash_result

# Fixed: Use secrets module for cryptographic randomness
def secure_random_generation():
    # Fixed: Use secrets for security-sensitive randomness
    secure_token = secrets.token_hex(16)
    secure_bytes = secrets.token_bytes(16)
    secure_url = secrets.token_urlsafe(16)

    return secure_token, secure_bytes, secure_url

# Fixed: Use f-strings or .format()
def secure_string_formatting(name, value):
    # Fixed: Use f-strings (Python 3.6+)
    result = f"Name: {name}, Value: {value}"

    # Or use .format()
    result = "Name: {}, Value: {}".format(name, value)

    return result

CVE Examples

No specific CVEs are listed in the MITRE database for this CWE. However, the pattern is associated with:

  • Buffer overflow vulnerabilities from gets(), strcpy(), sprintf()
  • Cryptographic weaknesses from MD5, SHA1, DES usage
  • Thread safety issues from deprecated thread control methods

References

  1. MITRE Corporation. "CWE-477: Use of Obsolete Function." https://cwe.mitre.org/data/definitions/477.html
  2. CERT C Secure Coding Standard. "MSC24-C. Do not use deprecated or obsolescent functions."
  3. OWASP Top Ten 2025 - A03: Software Supply Chain Failures.