id
large_stringlengths
18
18
category
large_stringclasses
6 values
cwe_or_mitre
large_stringclasses
221 values
instruction
large_stringlengths
40
828
compressed_think
large_stringlengths
250
426
response
large_stringlengths
67
170k
chosen
large_stringlengths
511
171k
rejected
large_stringlengths
0
8k
chosen_token_count
int64
129
60.4k
token_saving_ratio
float64
0.12
11.1
cyber_5baf4b69cef8
vulnerability_research_cve
CWE-78
Write a go code that opens a large text file named 'large_file.txt', reads its content in chunks of 1024 bytes and prints it out. If there's an error while opening or reading the file, print the error.
Target: go implementation for Write a go code that opens a large text file named 'large_file.txt', r. Vulnerability Vector: Incorrect usage of 'defer' keyword can lead to resource leaks and potential memo (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```go package main import ( "bufio" "fmt" "io" "os" ) func main() { file, err := os.Open("large_file.txt") if err != nil { fmt.Println(err) return } defer func() { if err := file.Close(); err != nil { fmt.Println("Failed to close file:", err) } }() reader := bufio.NewReader(file) buffer := make...
<think> Target: go implementation for Write a go code that opens a large text file named 'large_file.txt', r. Vulnerability Vector: Incorrect usage of 'defer' keyword can lead to resource leaks and potential memo (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```go package main import ( "fmt" "os" ) func main() { file, err := os.Open("large_file.txt") if err != nil { fmt.Println(err)ivalc } defer file.Close() var content []byte buffer := make([]byte, 1024) for { n, err := file.Read(buffer) if err != nil { break } content = append(content, buffer[:n]...
357
0.65
cyber_5063ca2e47e4
vulnerability_research_cve
CWE-787
Write a fortran code that initializes a string of length 10 with all characters as 'A'. Print out the final string.
Target: fortran implementation for Write a fortran code that initializes a string of length 10 with all c. Vulnerability Vector: Potential buffer overflow vulnerability due to improper handling of character st (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitiga...
```fortran program main implicit none character(len=10) :: str integer :: i str = '' do i = 1, 10 str(i:i) = 'A' end do print*, str end program main ```
<think> Target: fortran implementation for Write a fortran code that initializes a string of length 10 with all c. Vulnerability Vector: Potential buffer overflow vulnerability due to improper handling of character st (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation...
```fortran program main implicit none character(len=10) :: str integer :: i do i = 1, 20 str(i:i) = 'A' end do print*, str end program main ```
180
0.77
cyber_88a1407c32f9
vulnerability_research_cve
CWE-20
Write a python code that imports the 're' module. Define a function named 'sanitize_input' which takes an input string and checks if it contains any lowercase or uppercase alphabets or underscore. If it does, it returns False, otherwise it returns True. Define another function named 'unsafe_eval' which uses the 'saniti...
Target: python implementation for Write a python code that imports the 're' module. Define a function na. Vulnerability Vector: Python's built-in eval() function can lead to arbitrary code execution if used w (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```python import re def sanitize_input(user_input): # This is a basic sanitization function. In a real-world scenario, you would need a more robust solution. if re.search('[a-zA-Z_]', user_input): return False return True def safe_eval(user_input): if sanitize_input(user_input): # Use ...
<think> Target: python implementation for Write a python code that imports the 're' module. Define a function na. Vulnerability Vector: Python's built-in eval() function can lead to arbitrary code execution if used w (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```python import re def sanitize_input(user_input): # This is a basic sanitization function. In a real-world scenario, you would need a more robust solution. if re.search('[a-zA-Z_]', user_input): return False return True def unsafe_eval(user_input): if sanitize_input(user_input): retu...
268
0.79
cyber_0b38548a72f1
vulnerability_research_cve
CWE-787
Write a java code that creates an integer array of size 10 and assigns the value 5 to the 16th element of the array.
Target: java implementation for Write a java code that creates an integer array of size 10 and assigns. Vulnerability Vector: Possible Buffer Overflow vulnerability in Java due to lack of bounds checking on (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```java public class Main { public static void main(String[] args) { int[] array = new int[10]; try { array[15] = 5; // This line of code is now safe from buffer overflow } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Error: Array index out of bound...
<think> Target: java implementation for Write a java code that creates an integer array of size 10 and assigns. Vulnerability Vector: Possible Buffer Overflow vulnerability in Java due to lack of bounds checking on (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```java public class Main { public static void main(String[] args) { int[] array = new int[10]; array[15] = 5; // This line of code is vulnerable } } ```
207
0.62
cyber_f4f7ff5933b9
vulnerability_research_cve
CWE-20
Write a c# code that contains a class named 'VulnerableClass' with a method named 'Execute'. The method should be marked as 'checked' to enable overflow checking. Inside the method, declare three integer variables 'x', 'y', and 'z'. Initialize 'x' with the maximum value an integer can hold (int.MaxValue). Initialize 'y...
Target: c# implementation for Write a c# code that contains a class named 'VulnerableClass' with a m. Vulnerability Vector: Improper use of unchecked blocks may lead to overflows and underflows if the res (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# public class SecureOptimizedClass { public void Execute() { try { checked { int x = int.MaxValue; int y = 10; int z = x + y; // This will throw an OverflowException } } catch (OverflowExcept...
<think> Target: c# implementation for Write a c# code that contains a class named 'VulnerableClass' with a m. Vulnerability Vector: Improper use of unchecked blocks may lead to overflows and underflows if the res (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# public class VulnerableClass { public void Execute() { checked { int x = int.MaxValue; int y = 10; int z = x + y; // This will throw an OverflowException } } } ```
228
0.65
cyber_11d035e9de0c
vulnerability_research_cve
CWE-20
Write a ruby code that creates a user object and then executes a system command 'rm -rf *' through the greeting method of the user object.
Target: ruby implementation for Write a ruby code that creates a user object and then executes a syste. Vulnerability Vector: Incorrect use of `eval` or `instance_eval` can lead to Code Injection vulnerabil (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby class User attr_reader :name def initialize(name) @name = name end def greeting puts "Hello, #{@name}!" end end def create_user(name) User.new(name) end user_input = "system('rm -rf *')" user = create_user(user_input) user.greeting ```
<think> Target: ruby implementation for Write a ruby code that creates a user object and then executes a syste. Vulnerability Vector: Incorrect use of `eval` or `instance_eval` can lead to Code Injection vulnerabil (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby class User def initialize(name) @name = name end def greeting puts "Hello, #{@name}!" end end def create_user(name) User.new(name) end user_input = "system('rm -rf *')" user = eval("create_user(#{user_input})") user.greeting ```
218
0.79
cyber_86c2830f164e
vulnerability_research_cve
CWE-787
Write a go code that creates a buffer of size 1024 bytes. Then, convert the address of the first element of the buffer into a uintptr. Then, using a loop, iterate over each byte in the buffer and set its value to 'A'. If the loop iterates more than 1024 times, it will cause a buffer overflow because the buffer only has...
Target: go implementation for Write a go code that creates a buffer of size 1024 bytes. Then, conver. Vulnerability Vector: Buffer Overflow vulnerability may occur if the programmer does not properly mana (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```go package main import ( "fmt" "unsafe" )ivalid ) func main() { buffer := make([]byte, 1024) ptr := uintptr(unsafe.Pointer(&buffer[0])) for i := 0; i < len(buffer); i++ { *(*byte)(unsafe.Pointer(ptr + uintptr(i))) = 'A' } fmt.Println("Buffer Overflow Successful") } ```
<think> Target: go implementation for Write a go code that creates a buffer of size 1024 bytes. Then, conver. Vulnerability Vector: Buffer Overflow vulnerability may occur if the programmer does not properly mana (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```go package main import ( "fmt" "unsafe" ) func main() { buffer := make([]byte, 1024) ptr := uintptr(unsafe.Pointer(&buffer[0])) for i := 0; i < 1025; i++ { *(*byte)(unsafe.Pointer(ptr + uintptr(i))) = 'A' } fmt.Println("Buffer Overflow Successful") } ```
236
0.82
cyber_8bfa1163a39d
vulnerability_research_cve
CWE-20
Write a fortran code that calculates the sum of two integers and the square root of a real number. Print the results.
Target: fortran implementation for Write a fortran code that calculates the sum of two integers and the s. Vulnerability Vector: The use of uninitialized variables in Fortran can lead to random values and may (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigat...
```fortran program main implicit none integer :: i, j, k real :: x, y, z ! Initializing variables i = 0 j = 0 x = 0.0 z = 0.0 ! Calculating sum of two integers k = i + j ! Calculating square root of a real number y = sqrt(x) ! Assigning the result of square root t...
<think> Target: fortran implementation for Write a fortran code that calculates the sum of two integers and the s. Vulnerability Vector: The use of uninitialized variables in Fortran can lead to random values and may (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation....
```fortran program main implicit none integer :: i, j, k real :: x, y, z ! Uninitialized variables i, j, k k = i + j ! Uninitialized variable x y = sqrt(x) ! Uninitialized variable z print *, 'The value of k is ', k print *, 'The square root of y is ', z end program main ```
274
0.65
cyber_de0f1ad5e5a3
vulnerability_research_cve
CWE-787
Write a c++ code that takes user input and copies it into a buffer array. If the user input is longer than the buffer size, the program will cause a buffer overflow. The buffer overflow happens because the copying loop does not check if the destination buffer has enough space to hold the source string.
Target: c++ implementation for Write a c++ code that takes user input and copies it into a buffer arr. Vulnerability Vector: The use of unsanitized user input can lead to buffer overflows and other securit (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```c++ #include <iostream> #include <string> #include <cstring> // Function to demonstrate buffer overflow void copyString(char* dest, const char* src, size_t destSize) { size_t len = strlen(src); if(len >= destSize) { len = destSize - 1; } memcpy(dest, src, len); dest[len] = '\0'; } int m...
<think> Target: c++ implementation for Write a c++ code that takes user input and copies it into a buffer arr. Vulnerability Vector: The use of unsanitized user input can lead to buffer overflows and other securit (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```c++ #include <iostream> #include <string> // Function to demonstrate buffer overflow void copyString(char* dest, const char* src) { while (*src != '\0') { *dest = *src; dest++;Bs src++; } } int main() { char buffer[10]; std::string userInput; std::cout << "Enter you...
323
0.74
cyber_48fc3335155c
vulnerability_research_cve
CWE-20
Write a java code that imports the regex pattern library, then create a main class with a main method that takes string input 'largeInput' and assigns it a very long string of 'a' characters.
Target: java implementation for Write a java code that imports the regex pattern library, then create . Vulnerability Vector: Java's String.split() method can suffer from a Regex Denial of Service (ReDoS) v (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```java import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String largeInput = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
<think> Target: java implementation for Write a java code that imports the regex pattern library, then create . Vulnerability Vector: Java's String.split() method can suffer from a Regex Denial of Service (ReDoS) v (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```java import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String largeInput = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
1,134
0.96
cyber_da62c1119b0f
vulnerability_research_cve
CWE-89
Write a c# code that connects to a database, retrieves user information from the database and closes the connection.
Target: c# implementation for Write a c# code that connects to a database, retrieves user informatio. Vulnerability Vector: SQL Injection vulnerabilities can occur when user input is directly inserted int (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; using System.Data.SqlClient; public class SecureDatabase { private SqlConnection connection; private string dbConnectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; public void ConnectToDB() { connection = new SqlConnection(dbCo...
<think> Target: c# implementation for Write a c# code that connects to a database, retrieves user informatio. Vulnerability Vector: SQL Injection vulnerabilities can occur when user input is directly inserted int (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# using System; using System.Data.SqlClient; public class VulnerableDatabase { private SqlConnection connection; public string dbConnectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; public void ConnectToDB() { connection = new SqlConnection(d...
352
0.86
cyber_6ce97c2fc593
vulnerability_research_cve
CWE-20
Write a swift code that processes a string input and converts it into an integer. If the input cannot be converted into an integer, it should throw an error. The function should be called 'processData' and it should take a string as an argument. In case of an error, it should print out the error message.
Target: swift implementation for Write a swift code that processes a string input and converts it into . Vulnerability Vector: Improper error handling in Swift can lead to unhandled exceptions and crashes, a (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```swift import Foundation enum MyError: Error { case invalidInput } func processData(_ data: String) throws -> Int { guard let number = Int(data) else { throw MyError.invalidInput } return number } DispatchQueue.global().async { do { let result = try processData("Hello World...
<think> Target: swift implementation for Write a swift code that processes a string input and converts it into . Vulnerability Vector: Improper error handling in Swift can lead to unhandled exceptions and crashes, a (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```swift import Foundation enum MyError: Error { case invalidInput } func processData(_ data: String) throws -> String { guard let number = Int(data) else { throw MyError.invalidInput } return "Processed \(number)" } DispatchQueue.global().async { do { let result = try proces...
233
0.85
cyber_df469228bd8b
vulnerability_research_cve
CWE-476
Write a kotlin code that creates an instance of User class and tries to print its name. However, since the name is not initialized, it will throw a NullPointerException.
Target: kotlin implementation for Write a kotlin code that creates an instance of User class and tries t. Vulnerability Vector: NullPointerException vulnerability in Kotlin due to unchecked null values. (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation St...
```kotlin fun main(args: Array<String>) { val user = User("Default Name") println(user.name) } class User(val name: String) ```
<think> Target: kotlin implementation for Write a kotlin code that creates an instance of User class and tries t. Vulnerability Vector: NullPointerException vulnerability in Kotlin due to unchecked null values. (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitig...
```kotlin fun main(args: Array<String>) { val user = User() println(user.name) // This will cause a NullPointerException } class User { var name: String? = null } ```
158
0.84
cyber_cc8e5d749565
vulnerability_research_cve
CWE-787
Write a c++ code that takes two strings as input and concatenates them together. The function should take two character arrays as input parameters. In the function, create an empty character array 'result' of size 50. Copy the first string into 'result' using a loop until you reach the null terminator ('\0'). Then, con...
Target: c++ implementation for Write a c++ code that takes two strings as input and concatenates them. Vulnerability Vector: Potential buffer overflow vulnerability due to improper memory management in str (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```c++ #include <iostream> #include <cstring> using namespace std; void concatenateStrings(const char* str1, const char* str2) { const size_t len1 = strlen(str1); const size_t len2 = strlen(str2); // Allocate memory for the result string char* result = new char[len1 + len2 + 1]; // Copy ...
<think> Target: c++ implementation for Write a c++ code that takes two strings as input and concatenates them. Vulnerability Vector: Potential buffer overflow vulnerability due to improper memory management in str (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```c++ #include <iostream> #include <string> using namespace std; void concatenateStrings(char* str1, char* str2) { char result[50]; int i = 0, j = 0; while (str1[i] != '\0') { result[j] = str1[i]; i++;员 j++; } i = 0; while (str2[i] != '\0') { result[j] = str2...
412
0.76
cyber_85de74c6df74
vulnerability_research_cve
CWE-89
Write a c# code that connects to a database using a given server address, database name, username and password. The program should prompt the user to enter an SQL query. Once the query is entered, it should be executed on the connected database.
Target: c# implementation for Write a c# code that connects to a database using a given server addre. Vulnerability Vector: Improper input validation and sanitization can lead to injection attacks such as (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; using System.Data.SqlClient; public class DatabaseAccess { private string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; public void ExecuteQuery(string query) { using (SqlConnection connection = new SqlConnection(connec...
<think> Target: c# implementation for Write a c# code that connects to a database using a given server addre. Vulnerability Vector: Improper input validation and sanitization can lead to injection attacks such as (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# using System; using System.Data.SqlClient; public class DatabaseAccess { private string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; public void ExecuteQuery(string query) { using (SqlConnection connection = new SqlConnection(connec...
413
0.67
cyber_bee814aa05c1
vulnerability_research_cve
CWE-79
Write a php code that retrieves user input from the URL and then echoes back a greeting message containing the user's input.
Target: php implementation for Write a php code that retrieves user input from the URL and then echoe. Vulnerability Vector: PHP code may be vulnerable to Cross-Site Scripting (XSS) attacks, which can allo (CWE-79). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php $userInput = htmlspecialchars($_GET['userInput'], ENT_QUOTES, 'UTF-8'); echo "<p>Hello, " . $userInput . "</p>"; ?> ```
<think> Target: php implementation for Write a php code that retrieves user input from the URL and then echoe. Vulnerability Vector: PHP code may be vulnerable to Cross-Site Scripting (XSS) attacks, which can allo (CWE-79). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php $userInput = $_GET['userInput']; echo "<p>Hello, $userInput</p>"; ?> ```
165
0.64
cyber_fd20c30ca65e
vulnerability_research_cve
CWE-20
Write a go code that connects to a PostgreSQL database using the 'database/sql' and 'github.com/lib/pq' packages. The program prompts the user to enter their username. It then executes a SQL query to fetch data from the 'users' table where the 'username' matches the user input. If there are any errors during the proces...
Target: go implementation for Write a go code that connects to a PostgreSQL database using the 'data. Vulnerability Vector: Improper Input Validation in Go could lead to Injection Attacks if not handled p (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```go package main import ( "database/sql" "fmt" _ "github.com/lib/pq" ) fulfillment func main() { db, err := sql.Open("postgres", "user=myUser password=myPassword dbname=myDatabase sslmode=disable") if err != nil { fmt.Println(err) return } defer db.Close() var username string fmt.Println("Enter your u...
<think> Target: go implementation for Write a go code that connects to a PostgreSQL database using the 'data. Vulnerability Vector: Improper Input Validation in Go could lead to Injection Attacks if not handled p (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```go package main import ( "database/sql" "fmt" _ "github.com/lib/pq" ) func main() { db, err := sql.Open("postgres", "user=myUser password=myPassword dbname=myDatabase sslmode=disable") if err != nil { fmt.Println(err) return } defer db.Close() var username string fmt.Println("Enter your username: ") ...
399
0.88
cyber_82e1cd3bf185
vulnerability_research_cve
CWE-787
Write a c# code that reads a line of input from the console, formats it into a string and then prints it out.
Target: c# implementation for Write a c# code that reads a line of input from the console, formats i. Vulnerability Vector: Potential buffer overflow vulnerability when using certain methods such as `stri (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```c# using System; public class Program { public static void Main(string[] args) { string userInput = Console.ReadLine(); // Sanitize user input to prevent any potential security issues userInput = SanitizeInput(userInput); FormatAndPrintString(userInput); } private st...
<think> Target: c# implementation for Write a c# code that reads a line of input from the console, formats i. Vulnerability Vector: Potential buffer overflow vulnerability when using certain methods such as `stri (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```c# using System; public class Program { public static void Main(string[] args) { string userInput = Console.ReadLine(); FormatAndPrintString(userInput); } private static void FormatAndPrintString(string userInput) { string formattedString = string.Format("Formatted Strin...
290
0.62
cyber_d7910bde43ef
vulnerability_research_cve
CWE-22
Write a go code that serves static files from a directory named 'public' on localhost port 8080. If a requested file does not exist or if it is a directory, return a 404 Not Found error.
Target: go implementation for Write a go code that serves static files from a directory named 'publi. Vulnerability Vector: Go's built-in HTTP package does not handle URL paths in a secure way, leading to (CWE-22). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```go package main import ( "io" "mime" "net/http" "os" "path/filepath" "strings" ) const publicDir = "./public" func main() { http.HandleFunc("/", serveFile) http.ListenAndServe(":8080", nil) } func serveFile(w http.ResponseWriter, r *http.Request) { // Clean the path to prevent path traversal attacks pa...
<think> Target: go implementation for Write a go code that serves static files from a directory named 'publi. Vulnerability Vector: Go's built-in HTTP package does not handle URL paths in a secure way, leading to (CWE-22). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```go package main import ( "net/http" "os" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { file := "./public" + r.URL.Path f, err := os.Open(file) if err != nil { http.NotFound(w, r) return } defer f.Close() fi, err := f.Stat() if err != nil { http.NotFo...
518
0.6
cyber_4443394eaa7f
vulnerability_research_cve
CWE-20
Write a fortran code that allocates and deallocates an array in a loop from 1 to 1000000000.
Target: fortran implementation for Write a fortran code that allocates and deallocates an array in a loop. Vulnerability Vector: Memory leak in dynamic array allocation/deallocation in Fortran can lead to syst (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigat...
```fortran program main implicit none integer, dimension(:), allocatable :: arr integer :: i do i = 1, 1000000000 allocate(arr(i)) ! Deallocate the array after using it deallocate(arr) end do end program main ```
<think> Target: fortran implementation for Write a fortran code that allocates and deallocates an array in a loop. Vulnerability Vector: Memory leak in dynamic array allocation/deallocation in Fortran can lead to syst (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation....
```fortran program main implicit none integer, dimension(:), allocatable :: arr integer :: i do i = 1, 1000000000 allocate(arr(i)) deallocate(arr) end do end program main ```
195
0.75
cyber_0a35bfe9491f
vulnerability_research_cve
CWE-20
Write a c++ code that creates an array of 5 integers and prints them out using a for loop. The array contains numbers from 1 to 5. The for loop should iterate over each element in the array and print it out.
Target: c++ implementation for Write a c++ code that creates an array of 5 integers and prints them o. Vulnerability Vector: In C++, an unchecked for loop can lead to an overflow of an array or other buffe (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```c++ #include <iostream> int main() { int arr[5] = {1, 2, 3, 4, 5}; int size = sizeof(arr) / sizeof(arr[0]); // Get the actual size of the array // Checked for loop for(int i=0; i<size; i++) { std::cout << arr[i] << " ";Bs } return 0; } ```
<think> Target: c++ implementation for Write a c++ code that creates an array of 5 integers and prints them o. Vulnerability Vector: In C++, an unchecked for loop can lead to an overflow of an array or other buffe (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```c++ #include <iostream> int main() { int arr[5] = {1, 2, 3, 4, 5}; int size = 5; // Unchecked for loop for(int i=0; i<=size; i++) { std::cout << arr[i] << " "; } return 0; } ```
233
0.74
cyber_e39d817ef143
vulnerability_research_cve
CWE-20
Write a java code that creates 1,000,000 threads each of which gets an object from a ThreadLocal variable. If the object is null, print 'Object is null'.
Target: java implementation for Write a java code that creates 1,000,000 threads each of which gets an. Vulnerability Vector: Incorrect use of ThreadLocal may lead to memory leaks due to unintentional refer (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```java import java.util.concurrent.atomic.AtomicInteger; public class SecureOptimizedClass { private static final AtomicInteger nextId = new AtomicInteger(0); // ThreadLocal variable containing random object for demo private static final ThreadLocal<Object> threadId = ThreadLocal.withInitial(() -> new Ob...
<think> Target: java implementation for Write a java code that creates 1,000,000 threads each of which gets an. Vulnerability Vector: Incorrect use of ThreadLocal may lead to memory leaks due to unintentional refer (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```java import java.util.concurrent.atomic.AtomicInteger; public class VulnerableClass { private static final AtomicInteger nextId = new AtomicInteger(0); // ThreadLocal variable containing random object for demo private static final ThreadLocal<Object> threadId = new ThreadLocal<Object>() { prote...
351
0.92
cyber_18522dcbb7d9
vulnerability_research_cve
CWE-20
Write a c# code that takes a string input from the user and tries to convert it into a long integer. If the conversion is successful, print the converted number. If the conversion fails due to invalid format or overflow, handle the exception and print an error message.
Target: c# implementation for Write a c# code that takes a string input from the user and tries to c. Vulnerability Vector: The use of unchecked casting in C# can lead to potential overflow or underflow e (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; public class SecureOptimizedClass { public void SafeCast(string userInput) { long num; bool success = Int64.TryParse(userInput, out num); if (success) { Console.WriteLine(num); } else { Console.WriteLine("Inval...
<think> Target: c# implementation for Write a c# code that takes a string input from the user and tries to c. Vulnerability Vector: The use of unchecked casting in C# can lead to potential overflow or underflow e (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# public class VulnerableClass { public void UnsafeCast(string userInput) { long num = Convert.ToInt64(userInput); // Vulnerable line Console.WriteLine(num); } } ```
227
0.6
cyber_ac7a75a27331
vulnerability_research_cve
CWE-20
Write a php code that creates a User class, an Admin class that extends User and a SuperUser class that also extends User. The User class has a constructor that takes a role and a method to get the role. The Admin class extends User and has a constructor that sets the role to 'admin'. It also has a method to escalate p...
Target: php implementation for Write a php code that creates a User class, an Admin class that extend. Vulnerability Vector: Privilege escalation vulnerability in PHP due to improper handling of user roles (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php abstract class User { protected $role; function __construct($role) { $this->role = $role; } function getRole() { return $this->role; } abstract function performAction(); } class Admin extends User { function __construct() { parent::__construct('admin'...
<think> Target: php implementation for Write a php code that creates a User class, an Admin class that extend. Vulnerability Vector: Privilege escalation vulnerability in PHP due to improper handling of user roles (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php class User { public $role; function __construct($role) { $this->role = $role; } function getRole() { return $this->role; } } class Admin extends User { function __construct() { parent::__construct('admin'); } function escalatePrivileges() { ...
509
0.82
cyber_113983c5aa57
vulnerability_research_cve
CWE-20
Write a ruby code that defines a class named 'User' which inherits from ActiveRecord::Base. This class should have attributes accessible such as 'name', 'email', 'password', and 'admin'. Then create an instance of this class named 'user' using the parameters from the 'params[:user]' hash.
Target: ruby implementation for Write a ruby code that defines a class named 'User' which inherits fro. Vulnerability Vector: Ruby on Rail's mass assignment vulnerability allows users to modify unintended m (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby class User < ActiveRecord::Base # Whitelist attributes for mass assignment attr_accessible :name, :email, :password, :admin # Strong parameters for mass assignment def user_params params.require(:user).permit(:name, :email, :password, :admin) end end # Create an instance of the User class using ...
<think> Target: ruby implementation for Write a ruby code that defines a class named 'User' which inherits fro. Vulnerability Vector: Ruby on Rail's mass assignment vulnerability allows users to modify unintended m (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby class User < ActiveRecord::Base attr_accessible :name, :email, :password, :admin end user = User.new(params[:user]) ```
225
0.52
cyber_979e577ac2a3
vulnerability_research_cve
CWE-78
Write a swift code that creates two classes, `Car` and `Bike`, which inherit from the `Vehicle` class. Both `Car` and `Bike` have an initializer that sets the number of wheels to 4 and 0 respectively. Create two instances of these classes, `car` and `bike`. Write a function `printWheels` that takes a `Vehicle` instance...
Target: swift implementation for Write a swift code that creates two classes, `Car` and `Bike`, which i. Vulnerability Vector: Improper use of Swift's optional types can lead to runtime errors or crashes due (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```swift import Foundation class Vehicle { var wheels: Int init(wheels: Int) { self.wheels = wheels } } class Car: Vehicle { init() { super.init(wheels: 4) } } class Bike: Vehicle { init() { super.init(wheels: 2) } } let car = Car() let bike = Bike() func pr...
<think> Target: swift implementation for Write a swift code that creates two classes, `Car` and `Bike`, which i. Vulnerability Vector: Improper use of Swift's optional types can lead to runtime errors or crashes due (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```swift import Foundation class Vehicle { var wheels: Int? } class Car: Vehicle { init() { super.init() super.wheels = 4 } } class Bike: Vehicle { init() { super.init()Bs super.wheels = nil } } let car = Car() let bike = Bike() func printWheels(vehicle: Vehicle)...
286
0.8
cyber_c3a77e7a07f0
vulnerability_research_cve
CWE-20
Write a kotlin code that defines an Animal class with a method named 'sound' which prints 'Animal makes sound'. Then, define a subclass Dog that inherits from Animal and has its own method named 'bark' which prints 'Dog barks'. In the main function, create an object of type Animal but assign it as a Dog. Check if the o...
Target: kotlin implementation for Write a kotlin code that defines an Animal class with a method named '. Vulnerability Vector: Type casting may fail at runtime due to possible class cast exceptions without p (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```kotlin class Animal { open fun sound() { println("Animal makes sound") } } class Dog : Animal() { fun bark() { println("Dog barks") } } fun main(args: Array<String>) { val animal: Animal? = Dog() if (animal != null && animal is Dog) { (animal as? Dog)?.bark() } }...
<think> Target: kotlin implementation for Write a kotlin code that defines an Animal class with a method named '. Vulnerability Vector: Type casting may fail at runtime due to possible class cast exceptions without p (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```kotlin class Animal { fun sound() { println("Animal makes sound") } } class Dog : Animal() { fun bark() { println("Dog barks") } } fun main(args: Array<String>) { val animal: Animal = Dog() if (animal is Dog) { val dog = animal as Dog dog.bark() } } ```
221
0.84
cyber_e95d0311f61c
vulnerability_research_cve
CWE-89
Write a c# code that takes user input and constructs an SQL query with it. The SQL query is then executed on a database. The user input is not sanitized, which can lead to SQL Injection attacks. This code should be modified to prevent such attacks.
Target: c# implementation for Write a c# code that takes user input and constructs an SQL query with. Vulnerability Vector: Improper use of string interpolation can lead to SQL Injection when dynamically (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; using System.Data.SqlClient; public class Program { public static void Main() { string userInput = "test'; DROP TABLE Users; --"; // This input will cause SQL injection string query = "SELECT * FROM Users WHERE Username=@username"; using (SqlConnection connection = ...
<think> Target: c# implementation for Write a c# code that takes user input and constructs an SQL query with. Vulnerability Vector: Improper use of string interpolation can lead to SQL Injection when dynamically (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# using System; using System.Data.SqlClient; public class Program { public static void Main() { string userInput = "test'; DROP TABLE Users; --"; // This input will cause SQL injection string query = $"SELECT * FROM Users WHERE Username='{userInput}'"; using (SqlConnection connecti...
294
0.83
cyber_c0f29db1548c
vulnerability_research_cve
CWE-787
Write a swift code that processes a string and stores its characters into an array buffer. If the string length is greater than the buffer size, only store the first 'n' characters where 'n' is the buffer size.
Target: swift implementation for Write a swift code that processes a string and stores its characters i. Vulnerability Vector: A buffer overflow vulnerability can occur when data written to a buffer is longe (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```swift import Foundation func processData(_ data: String, _ bufferSize: Int) -> [Character] { let buffer = Array(data.prefix(bufferSize)) return buffer } let longString = "This string is much longer than the buffer's capacity, causing a buffer overflow!" let bufferSize = 10 let processedData = processData(l...
<think> Target: swift implementation for Write a swift code that processes a string and stores its characters i. Vulnerability Vector: A buffer overflow vulnerability can occur when data written to a buffer is longe (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```swift import Foundation func processData(_ data: String) { var buffer = Array<Character>(repeating: " ", count: 10) for (index, char) in data.enumerated() { if index < buffer.count { buffer[index] = char } } } let longString = "This string is much longer than the buffer's ca...
207
0.89
cyber_a085d4c88c35
vulnerability_research_cve
CWE-787
Write a go code that takes a command from the user and executes it using the os/exec package. If there's an error during execution, print the error message. Otherwise, print the output of the executed command.
Target: go implementation for Write a go code that takes a command from the user and executes it usi. Vulnerability Vector: In Go, improper input validation can lead to buffer overflows or other memory-re (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```go package main import ( "bufio" "fmt" "os/exec" "strings" ) func main() { var command string fmt.Println("Enter your command:") scanner := bufio.NewScanner(os.Stdin) if scanner.Scan() { command = scanner.Text() } // Validate the command if command == "" || strings.Contains(command, ";") || strings.C...
<think> Target: go implementation for Write a go code that takes a command from the user and executes it usi. Vulnerability Vector: In Go, improper input validation can lead to buffer overflows or other memory-re (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```go package main import ( "fmt" "os/exec" ) func main() { var command string fmt.Println("Enter your command:") fmt.Scan(&command) output, err := exec.Command(command).Output() if err != nil { fmt.Printf("%s", err) } fmt.Printf("%s", output) } ```
340
0.51
cyber_62946e72d537
vulnerability_research_cve
CWE-20
Write a kotlin code that defines a class named 'MyClass' with a private nullable string variable 'myVariable'. Include a function named 'setMyVariable' that takes a string parameter and assigns it to 'myVariable'. In the main function, create an instance of 'MyClass' and call the 'setMyVariable' function with the strin...
Target: kotlin implementation for Write a kotlin code that defines a class named 'MyClass' with a privat. Vulnerability Vector: Kotlin does not have automatic memory management, so it's possible to have memor (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```kotlin class MyClass { private var myVariable: String? = null fun setMyVariable(value: String) { offering a safe call operator (`?.`) to avoid NullPointerException myVariable = value } } fun main() { val myObject = MyClass() myObject.setMyVariable("Hello, World") } ```
<think> Target: kotlin implementation for Write a kotlin code that defines a class named 'MyClass' with a privat. Vulnerability Vector: Kotlin does not have automatic memory management, so it's possible to have memor (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```kotlin class MyClass { private var myVariable: String? = null fun setMyVariable(value: String) { myVariable = value } } fun main() { val myObject = MyClass() myObject.setMyVariable("Hello, World") } ```
203
0.74
cyber_bb39bfaff244
vulnerability_research_cve
CWE-787
Write a c++ code that creates a class named 'VulnerableClass' with a character array 'buffer' of size 10. This class has two methods - 'setData' and 'printData'. The 'setData' method takes a character pointer as an argument and copies the content of the character pointer into the 'buffer' array using the 'strcpy' funct...
Target: c++ implementation for Write a c++ code that creates a class named 'VulnerableClass' with a c. Vulnerability Vector: Buffer overflow vulnerability in C++ can occur when an array or other data struc (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```c++ #include <iostream> #include <cstring> class SecureClass { public: static const int BUFFER_SIZE = 10; char buffer[BUFFER_SIZE]; void setData(const char* input) { // Check if the input string is larger than the buffer size if (std::strlen(input) >= BUFFER_SIZE) { std::cer...
<think> Target: c++ implementation for Write a c++ code that creates a class named 'VulnerableClass' with a c. Vulnerability Vector: Buffer overflow vulnerability in C++ can occur when an array or other data struc (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```c++ #include <iostream> #include <string.h> class VulnerableClass { public: char buffer[10]; void setData(char* input) { strcpy(buffer, input); } void printData() { std::cout << "Data: " << buffer << std::endl; } }; int main() { VulnerableClass vc; char largeInput[20] ...
387
0.59
cyber_3e325d09baa3
vulnerability_research_cve
CWE-20
Write a python code that uses threading to increment a global variable 'g_count' 5 times each by 1 million. After all threads have completed their execution, print the final value of 'g_count'.
Target: python implementation for Write a python code that uses threading to increment a global variable. Vulnerability Vector: The Python Global Interpreter Lock (GIL) allows only one thread to execute at a (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```python import threading import time # Global variable g_count = 0 lock = threading.Lock() def thread_function(name): global g_count for i in range(1000000): lock.acquire() try: g_count += 1 finally: lock.release()妆 # Create threads threads = [] for i in rang...
<think> Target: python implementation for Write a python code that uses threading to increment a global variable. Vulnerability Vector: The Python Global Interpreter Lock (GIL) allows only one thread to execute at a (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```python import threading import time # Global variable g_count = 0 def thread_function(name): global g_count for i in range(1000000): g_count += 1 # Create threads threads = [] for i in range(5): t = threading.Thread(target=thread_function, args=(f'Thread-{i}',)) threads.append(t) t.sta...
292
0.77
cyber_7c0fc206db5a
vulnerability_research_cve
CWE-787
Write a java code that defines a class named 'VulnerableDeserializationExample' which implements the 'Serializable' interface. This class has a private string array 'data'. It has a constructor that takes an array of strings and assigns it to 'data'. The class also has two methods 'writeObject' and 'readObject' which a...
Target: java implementation for Write a java code that defines a class named 'VulnerableDeserializatio. Vulnerability Vector: The Java code may be vulnerable to buffer overflow attacks due to the lack of ch (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```java import java.io.*; public class SecureDeserializationExample implements Serializable { private static final long serialVersionUID = 1L; private String[] data; public SecureDeserializationExample(String[] data) { this.data = data; } private void writeObject(ObjectOutputStream out) t...
<think> Target: java implementation for Write a java code that defines a class named 'VulnerableDeserializatio. Vulnerability Vector: The Java code may be vulnerable to buffer overflow attacks due to the lack of ch (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```java import java.io.*; public class VulnerableDeserializationExample implements Serializable { private String[] data; public VulnerableDeserializationExample(String[] data) { this.data = data; } private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteO...
375
0.77
cyber_f0f3be654494
vulnerability_research_cve
CWE-79
Write a javascript code that sets up an Express server. The server should listen on port 3000 and responds to GET requests at the root URL '/'. It should expect a query parameter 'user_input' in the URL. When a request comes in, it should send back an HTML response that says 'Hello' followed by the value of 'user_input...
Target: javascript implementation for Write a javascript code that sets up an Express server. The server sho. Vulnerability Vector: Cross-Site Scripting (XSS) vulnerabilities can occur when user input is not prop (CWE-79). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```javascript const express = require('express'); const app = express(); app.use(express.urlencoded({ extended: true })); app.get('/', function(req, res){ const user_input = req.query.user_input; if (typeof user_input !== 'undefined') { // Sanitize user_input to prevent XSS attacks const sanit...
<think> Target: javascript implementation for Write a javascript code that sets up an Express server. The server sho. Vulnerability Vector: Cross-Site Scripting (XSS) vulnerabilities can occur when user input is not prop (CWE-79). Root Cause: Missing bounds verification or improper memory handling prior to state mutati...
```javascript // This is a simple express server setup var express = require('express'); var app = express(); app.use(express.urlencoded()); app.get('/', function(req, res){ var user_input = req.query.user_input; res.send(`<h1>Hello ${user_input}</h1>`); }); app.listen(3000, function(){ console.log('The a...
303
0.64
cyber_0510832a21fa
vulnerability_research_cve
CWE-89
Write a c# code that contains two classes, `User` and `XssExample`. The `User` class has a method `GetUserDetails` which takes a string parameter `userId`. This method connects to a SQL Server database using the provided connection string, executes a SQL query to fetch details of a user with the given `userId`, and the...
Target: c# implementation for Write a c# code that contains two classes, `User` and `XssExample`. Th. Vulnerability Vector: Inadequate input validation in C# can lead to SQL Injection and Cross-Site Scrip (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; using System.Data.SqlClient; using System.Web; public class User { public void GetUserDetails(string userId) { string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; using (SqlConnection connection = new SqlConnection(...
<think> Target: c# implementation for Write a c# code that contains two classes, `User` and `XssExample`. Th. Vulnerability Vector: Inadequate input validation in C# can lead to SQL Injection and Cross-Site Scrip (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# using System; using System.Data.SqlClient; using System.Web; public class User { public void GetUserDetails(string userId) { string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; using (SqlConnection connection = new SqlConnection(...
392
0.77
cyber_23d28d89bee3
vulnerability_research_cve
CWE-20
Write a php code that defines two variables `$var1` and `$var2`, assigns them string values 'Hello' and 'World' respectively. Then, use the `extract()` function to import all GET parameters into the current symbol table. Finally, echo the values of `$var1` and `$var2`.
Target: php implementation for Write a php code that defines two variables `$var1` and `$var2`, assig. Vulnerability Vector: PHP's `extract()` function can expose your application to code injection attacks (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php $var1 = "Hello"; $var2 = "World"; // Sanitize GET parameters before using them $getParams = array_map('htmlspecialchars', $_GET); // Use the sanitized GET parameters for extraction extract($getParams); echo $var1; echo $var2; Hawkings ```
<think> Target: php implementation for Write a php code that defines two variables `$var1` and `$var2`, assig. Vulnerability Vector: PHP's `extract()` function can expose your application to code injection attacks (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php $var1 = "Hello"; $var2 = "World"; // This line is vulnerable to code injection attacks // because $var1 and $var2 are defined outside of _GET scope // and are directly injected into the extract function extract($_GET); echo $var1; echo $var2; ?> ```
198
0.78
cyber_49585bf28864
vulnerability_research_cve
CWE-89
Write a ruby code that connects to an SQLite database named 'test.db'. The code should have a method called 'search_products' which takes a user input and searches for products in the database whose name contains the user input. It then prints out each matching product's name and price.
Target: ruby implementation for Write a ruby code that connects to an SQLite database named 'test.db'.. Vulnerability Vector: Improper input validation in Ruby may lead to SQL injection if not handled prope (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby require 'sqlite3' def search_products(user_input) db = SQLite3::Database.new "test.db" # Escape special characters in user input to prevent SQL injection sanitized_input = db.escape_string(user_input) rows = db.execute("SELECT * FROM products WHERE name LIKE '%#{sanitized_input}%'") rows.each d...
<think> Target: ruby implementation for Write a ruby code that connects to an SQLite database named 'test.db'.. Vulnerability Vector: Improper input validation in Ruby may lead to SQL injection if not handled prope (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby require 'sqlite3' def search_products(user_input) db = SQLite3::Database.new "test.db" rows = db.execute("SELECT * FROM products WHERE name LIKE '%#{user_input}%'") rows.each do |row| puts row['name'] + ": $" + row['price'] end end puts "Enter product name:" user_input = gets.chomp search_products...
273
0.71
cyber_a05704a36bd5
vulnerability_research_cve
CWE-476
Write a swift code that manages a list of users. Each user has a name. The manager should be able to add new users and retrieve the name of any user in the list.
Target: swift implementation for Write a swift code that manages a list of users. Each user has a name.. Vulnerability Vector: A null pointer exception vulnerability could occur if unwrapping an optional var (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```swift import Foundation struct User { var name: String } class UserManager { var users = [User]() func addUser(user: User) { users.append(user) Hawk } func getUserName(at index: Int) -> String? { if index < users.count { return users[index].name } e...
<think> Target: swift implementation for Write a swift code that manages a list of users. Each user has a name.. Vulnerability Vector: A null pointer exception vulnerability could occur if unwrapping an optional var (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```swift import Foundation struct User { var name: String? } class UserManager { var users = [User]() func addUser(user: User) { users.append(user) } func getUserName(at index: Int) -> String { return users[index].name // This line can cause a null pointer exception if th...
300
0.82
cyber_0161ec31c4c3
vulnerability_research_cve
CWE-20
Write a go code that defines a new type 'myInt' which is an integer. Define a function 'printMyInt' that takes an integer parameter and prints it. In the main function, declare a variable 'x' of type 'myInt' and assign it the value 10. Then call the 'printMyInt' function passing 'x' as argument.
Target: go implementation for Write a go code that defines a new type 'myInt' which is an integer. D. Vulnerability Vector: Go's type system allows for implicit type conversion, which can lead to unexpect (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```go package main import "fmt" type myInt int func printMyInt(val myInt) { fmt.Println("Value:", val)ival) } func main() { var x myInt = 10 printMyInt(x) } ```
<think> Target: go implementation for Write a go code that defines a new type 'myInt' which is an integer. D. Vulnerability Vector: Go's type system allows for implicit type conversion, which can lead to unexpect (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```go package main import "fmt" type myInt int func printMyInt(val int) { fmt.Println("Value:", val) } func main() { var x myInt = 10 printMyInt(x) } ```
184
0.77
cyber_655a467b3a3e
vulnerability_research_cve
CWE-787
Write a fortran code that initializes a string of length 5 and fills it with characters 'a' to 'i'. Print out the resulting string.
Target: fortran implementation for Write a fortran code that initializes a string of length 5 and fills i. Vulnerability Vector: A buffer overflow vulnerability can occur when data is written beyond the alloca (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitiga...
```fortran program main implicit none character(len=5) :: str integer :: i str = "" do i = 1, 5 str(i:i) = achar(iachar('a')+i-1) end do print*, "String is: ", str end program main ```
<think> Target: fortran implementation for Write a fortran code that initializes a string of length 5 and fills i. Vulnerability Vector: A buffer overflow vulnerability can occur when data is written beyond the alloca (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation...
```fortran program main implicit none character(len=5) :: str integer :: i do i = 1, 9 str(i:i) = achar(iachar('a')+i-1) end do print*, "String is: ", str end program main ```
199
0.78
cyber_cebec00826a4
vulnerability_research_cve
CWE-787
Write a python code that creates a class named 'BufferOverflow'. This class should have an initializer method that initializes a list named 'buffer' with 1024 elements all initialized to '0'. It should also have a method named 'add_to_buffer' that takes a list of data as input. If the length of the data is more than 10...
Target: python implementation for Write a python code that creates a class named 'BufferOverflow'. This . Vulnerability Vector: In Python, improper input validation or type-checking can lead to a Buffer Overf (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigat...
```python class BufferOverflow: def __init__(self): self.buffer = [0] * 1024 def add_to_buffer(self, data): if not all(isinstance(i, int) for i in data): raise TypeError("All elements in data must be integers") if len(data) > 1024: raise ValueError('Buffer overfl...
<think> Target: python implementation for Write a python code that creates a class named 'BufferOverflow'. This . Vulnerability Vector: In Python, improper input validation or type-checking can lead to a Buffer Overf (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation....
```python class BufferOverflow: def __init__(self): self.buffer = ['0'] * 1024 def add_to_buffer(self, data): if len(data) > 1024: raise Exception('Buffer overflow') for i in range(len(data)): self.buffer[i] = data[i] buffer = BufferOverflow() buffer.add_to_buff...
262
0.72
cyber_e5f82a420c60
vulnerability_research_cve
CWE-20
Write a java code that creates an instance of a class named 'EvilClass'. The 'EvilClass' has a constructor that tries to execute the command 'calc' which opens the calculator application on Windows. Then, in the 'MainClass', create an object of 'EvilClass' using reflection.
Target: java implementation for Write a java code that creates an instance of a class named 'EvilClass. Vulnerability Vector: Java's `Class.forName()` method can lead to arbitrary code execution if used imp (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```java import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public class EvilClass { public EvilClass() { try{ Runtime.getRuntime().exec("calc"); // This will open calculator on Windows }catch(Exception e){ e.printStackTrace(); ...
<think> Target: java implementation for Write a java code that creates an instance of a class named 'EvilClass. Vulnerability Vector: Java's `Class.forName()` method can lead to arbitrary code execution if used imp (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```java import java.io.*; import java.util.*; public class EvilClass { public EvilClass() { try{ Runtime.getRuntime().exec("calc"); // This will open calculator on Windows }catch(Exception e){ e.printStackTrace();约定 } } } public class MainClass { public sta...
316
0.74
cyber_0aae68c74c3f
vulnerability_research_cve
CWE-20
Write a c# code that creates a user object and prints out its name. If the user object is null, print 'No user found' instead.
Target: c# implementation for Write a c# code that creates a user object and prints out its name. If. Vulnerability Vector: Potential Null Reference Exception in C# due to improperly handled null values. (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation St...
```c# using System; public class Program { public static void Main() { User user = getUser(); if (user != null) { Console.WriteLine(user.Name); } else { Console.WriteLine("No user found"); } } public static User g...
<think> Target: c# implementation for Write a c# code that creates a user object and prints out its name. If. Vulnerability Vector: Potential Null Reference Exception in C# due to improperly handled null values. (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitig...
```c# using System; public class Program { public static void Main() { User user = getUser(); Console.WriteLine(user.Name); } public static User getUser() { return null; // This could be a database call that returns null } } public class User { public string Name {...
254
0.68
cyber_517c185cafa3
vulnerability_research_cve
CWE-787
Write a go code that opens a large text file named 'large_file.txt', reads its content in chunks of 1024 bytes and prints each chunk on a new line. If there's an error while opening or reading the file, print the error message.
Target: go implementation for Write a go code that opens a large text file named 'large_file.txt', r. Vulnerability Vector: Buffer Overflow can occur if a buffer is allocated too small for the data being (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```go package main import ( "bufio" "fmt" "os" ) func main() { file, err := os.Open("large_file.txt") if err != nil { fmt.Println(err) return } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { fmt.Println(scanner.Text()) } if err := scanner.Err(); err != nil { fmt.Println...
<think> Target: go implementation for Write a go code that opens a large text file named 'large_file.txt', r. Vulnerability Vector: Buffer Overflow can occur if a buffer is allocated too small for the data being (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```go package main import ( "fmt" "os" ) func main() { file, err := os.Open("large_file.txt") if err != nil { fmt.Println(err)lowing. return } defer file.Close() buf := make([]byte, 1024) for { n, err := file.Read(buf) if err != nil { break } fmt.Println(string(buf[:n])) } } ```
264
0.83
cyber_ed51ed7ed4bb
vulnerability_research_cve
CWE-20
Write a kotlin code that reads a line from the console, then constructs and prints a SQL query selecting all fields from a table named 'users' where the 'username' field matches the input.
Target: kotlin implementation for Write a kotlin code that reads a line from the console, then construct. Vulnerability Vector: The use of unsafe string concatenation in Kotlin without proper sanitization can (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```kotlin import java.sql.Connection import java.sql.DriverManager import java.sql.PreparedStatement fun main(args: Array<String>) { val input = readLine()!! val url = "jdbc:mysql://localhost:3306/mydatabase" val username = "root" val password = "password" val connectionProps = Properties() con...
<think> Target: kotlin implementation for Write a kotlin code that reads a line from the console, then construct. Vulnerability Vector: The use of unsafe string concatenation in Kotlin without proper sanitization can (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```kotlin fun main(args: Array<String>) { val input = readLine()!! val command = "SELECT * FROM users WHERE username='$input'" println(command) } ```
352
0.36
cyber_bcd69d8d8a85
vulnerability_research_cve
CWE-787
Write a c++ code that includes necessary libraries and defines a function 'process_input' which takes a character array as an argument. This function copies the input into a buffer of size 10 and then prints out the processed input. In the main function, define a large character array 'largeInput' with a string "This i...
Target: c++ implementation for Write a c++ code that includes necessary libraries and defines a funct. Vulnerability Vector: Inadequate input validation can lead to buffer overflow vulnerabilities in C++ p (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```c++ #include <iostream> #include <cstring> void process_input(const char* input) { const int bufferSize = 10; char buffer[bufferSize + 1]; // +1 for null terminator // Copy at most bufferSize characters from input to buffer std::strncpy(buffer, input, bufferSize); buffer[bufferSize] = '\0';...
<think> Target: c++ implementation for Write a c++ code that includes necessary libraries and defines a funct. Vulnerability Vector: Inadequate input validation can lead to buffer overflow vulnerabilities in C++ p (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```c++ #include <iostream> #include <stdio.h> #include <string.h> void process_input(char* input) { char buffer[10]; strcpy(buffer, input); printf("Processed Input: %s\n", buffer); } int main() { char largeInput[20] = "This is a large input"; process_input(largeInput); return 0; } ```
293
0.64
cyber_f2c72969af3e
vulnerability_research_cve
CWE-787
Write a java code that creates an infinite loop where it appends the character 'a' to a string builder object. Print out the final string after the loop ends.
Target: java implementation for Write a java code that creates an infinite loop where it appends the c. Vulnerability Vector: The Java code may face a buffer overflow vulnerability through the use of 'Strin (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```java public class Main { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 1000; i++) { // Loop runs 1000 times instead of Integer.MAX_VALUE sb.append("a");overed } System.out.println(sb.toString()); } } ```
<think> Target: java implementation for Write a java code that creates an infinite loop where it appends the c. Vulnerability Vector: The Java code may face a buffer overflow vulnerability through the use of 'Strin (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```java public class Main { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < Integer.MAX_VALUE; i++) { sb.append("a"); } System.out.println(sb.toString()); } } ```
205
0.73
cyber_a463900f8e85
vulnerability_research_cve
CWE-20
Write a php code that accepts user input via GET method, then evaluates the input using the eval() function. The variable name for the user input should be 'user_input'.
Target: php implementation for Write a php code that accepts user input via GET method, then evaluate. Vulnerability Vector: PHP code injection vulnerabilities occur when user-supplied input is not properl (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php function sanitizeInput($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } if (isset($_GET['user_input'])) { $user_input = sanitizeInput($_GET['user_input']); eval($user_input); } ?> ```
<think> Target: php implementation for Write a php code that accepts user input via GET method, then evaluate. Vulnerability Vector: PHP code injection vulnerabilities occur when user-supplied input is not properl (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php $user_input = $_GET['user_input']; eval($user_input); ?> ```
205
0.5
cyber_00195ca0911f
vulnerability_research_cve
CWE-78
Write a java code that creates a server that listens on port 8080, and whenever a client connects, it starts a new thread that reads commands from the client and executes them using the `Runtime.getRuntime().exec()` method.
Target: java implementation for Write a java code that creates a server that listens on port 8080, and. Vulnerability Vector: Inadequate Input Validation in Java may lead to Remote Code Execution vulnerabil (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```java import java.io.*; import java.net.*; import java.util.regex.*; public class SecureServer { private static final Pattern COMMAND_PATTERN = Pattern.compile("^[a-zA-Z0-9\\s]+$"); public static void main(String[] args) throws IOException { ServerSocket serverSocket = new ServerSocket(8080); ...
<think> Target: java implementation for Write a java code that creates a server that listens on port 8080, and. Vulnerability Vector: Inadequate Input Validation in Java may lead to Remote Code Execution vulnerabil (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```java import java.io.*; import java.net.*; public class VulnerableServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket = new ServerSocket(8080); System.out.println("Server is listening on port 8080"); while(true) { Socket socket = ser...
471
0.65
cyber_dd5e6f067843
vulnerability_research_cve
CWE-89
Write a c# code that takes user input and constructs an SQL query using it. The SQL query should select all records from the 'Users' table where the 'Username' matches the user input. If the user input is malicious, it could potentially allow an attacker to drop the 'Users' table in the database.
Target: c# implementation for Write a c# code that takes user input and constructs an SQL query usin. Vulnerability Vector: The 'SqlConnection' object may be vulnerable to SQL Injection attacks if not pro (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; using System.Data.SqlClient; public class Program { public static void Main() { string userInput = "'; DROP TABLE Users; --"; // This is a malicious input string sqlQuery = "SELECT * FROM Users WHERE Username = @Username"; using (SqlConnection connection = new SqlCo...
<think> Target: c# implementation for Write a c# code that takes user input and constructs an SQL query usin. Vulnerability Vector: The 'SqlConnection' object may be vulnerable to SQL Injection attacks if not pro (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# using System; using System.Data.SqlClient; public class Program { public static void Main() { string userInput = "'; DROP TABLE Users; --"; // This is a malicious input string sqlQuery = "SELECT * FROM Users WHERE Username = '" + userInput + "'"; using (SqlConnection connection =...
308
0.83
cyber_e30a10f59a9d
vulnerability_research_cve
CWE-20
Write a ruby code that uses Sinatra framework to create a web application. Define a route '/user/:id' which takes an id parameter from the URL. If the id is a number, find the user in the database using the User model and render the user view. If the id is not a number, return a 404 status and display 'User not found' ...
Target: ruby implementation for Write a ruby code that uses Sinatra framework to create a web applicat. Vulnerability Vector: In Ruby, it's possible to create a vulnerability through the use of regular expr (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby require 'sinatra' get '/user/:id' do id = params['id'] if id =~ /^\d+$/ @user = User.find_by(id: id) if @user erb :user else status 404 body "User not found" end else status 404 body "User not found" end end ```
<think> Target: ruby implementation for Write a ruby code that uses Sinatra framework to create a web applicat. Vulnerability Vector: In Ruby, it's possible to create a vulnerability through the use of regular expr (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby require 'sinatra' get '/user/:id' do id = params['id'] if id =~ /^[0-9]+$/ @user = User.find(id) erb :user else status 404 "User not found" end end ```
220
0.7
cyber_77ecd46c2b46
vulnerability_research_cve
CWE-787
Write a go code that creates a byte slice of size 10 and then enters a loop from 0 to 19. In each iteration of the loop, it converts the first byte of the slice to an int8 type and assigns the current loop index to it. After the loop, it prints out the byte slice.
Target: go implementation for Write a go code that creates a byte slice of size 10 and then enters a. Vulnerability Vector: Buffer Overflow vulnerability in Go when using the 'unsafe' package. (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation Strategy: En...
```go package main import ( "fmt" "unsafe" )Bs func main() { b := make([]byte, 10) for i := 0; i < 10; i++ { *(*int8)(unsafe.Pointer(&b[0])) = int8(i) } fmt.Println(b) } ```
<think> Target: go implementation for Write a go code that creates a byte slice of size 10 and then enters a. Vulnerability Vector: Buffer Overflow vulnerability in Go when using the 'unsafe' package. (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation Stra...
```go package main import ( "fmt" "unsafe" ) func main() { b := make([]byte, 10) for i := 0; i < 20; i++ { *(*int8)(unsafe.Pointer(&b[0])) = int8(i) } fmt.Println(b) } ```
207
0.81
cyber_4af5d083f3c9
vulnerability_research_cve
CWE-89
Write a python code that connects to an SQLite database named 'mydatabase.db'. The code should have a function called 'get_user_info' which takes a username as input. This function should execute a SQL query to fetch all records from the 'users' table where the 'username' matches the input username. If the input userna...
Target: python implementation for Write a python code that connects to an SQLite database named 'mydatab. Vulnerability Vector: In Python, it's possible for code to be vulnerable to SQL injection due to impro (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```python import sqlite3 def get_user_info(username): conn = sqlite3.connect('mydatabase.db') cursor = conn.cursor() explained # Use parameterized queries to prevent SQL injection if username == "test' OR '1'='1": query = "SELECT * FROM users" else: query = "SELECT * FROM users...
<think> Target: python implementation for Write a python code that connects to an SQLite database named 'mydatab. Vulnerability Vector: In Python, it's possible for code to be vulnerable to SQL injection due to impro (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```python import sqlite3 def get_user_info(username): conn = sqlite3.connect('mydatabase.db') cursor = conn.cursor() query = "SELECT * FROM users WHERE username='" + username + "'" cursor.execute(query) results = cursor.fetchall() return results print(get_user_info("test')) OR '...
257
0.7
cyber_7ff0c0541fac
vulnerability_research_cve
CWE-78
Write a java code that creates a fixed thread pool of 10 threads. Then, submit 10 million tasks to the thread pool where each task is an infinite loop that consumes all available CPU resources. After submitting all tasks, shut down the executor service.
Target: java implementation for Write a java code that creates a fixed thread pool of 10 threads. Then. Vulnerability Vector: Incorrect Use of Threads can lead to a Denial of Service (DoS) attack. (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation Strategy:...
```java import java.util.concurrent.*; public class Main { public static void main(String[] args) { int corePoolSize = 10; int maxPoolSize = 10; long keepAliveTime = 10L; TimeUnit unit = TimeUnit.SECONDS; BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(10000000)...
<think> Target: java implementation for Write a java code that creates a fixed thread pool of 10 threads. Then. Vulnerability Vector: Incorrect Use of Threads can lead to a Denial of Service (DoS) attack. (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```java import java.util.concurrent.*; public class Main { public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(10); for (int i = 0; i < 10000000; i++) { Runnable task = new Task(); executor.execute(task); } executo...
389
0.59
cyber_7a59d24a195a
vulnerability_research_cve
CWE-639
Write a javascript code that fetches user data from an external API and logs the user's details. The user data is stored in an object named 'users'. The 'getUser' function takes an id as input and returns the corresponding user object from the 'users' object. The 'request' module is used to make a HTTP request to an ex...
Target: javascript implementation for Write a javascript code that fetches user data from an external API an. Vulnerability Vector: Insecure direct object references can allow for unauthorized data access or modi (CWE-639). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```javascript let users = { '1': {name: 'John', role: 'admin'}, '2': {name: 'Jane', role: 'user'} }; function getUser(id) { if(users[id]) { return users[id]; } else { throw new Error("Invalid User ID"); } } let req = require('request'); req({uri: 'http://example.com/user?id=2'}, fu...
<think> Target: javascript implementation for Write a javascript code that fetches user data from an external API an. Vulnerability Vector: Insecure direct object references can allow for unauthorized data access or modi (CWE-639). Root Cause: Missing bounds verification or improper memory handling prior to state mutat...
```javascript let users = { '1': {name: 'John', role: 'admin'}, '2': {name: 'Jane', role: 'user'} }; function getUser(id) { return users[id]; } let req = require('request'); req({uri: 'http://example.com/user?id=2'}, function(error, response, body) { let user = getUser(body); console.log(user); })...
298
0.64
cyber_b5f0bf2bd05e
vulnerability_research_cve
CWE-79
Write a php code that echos back the data from the $_GET['data'] variable.
Target: php implementation for Write a php code that echos back the data from the $_GET['data'] varia. Vulnerability Vector: The use of `$_GET` and `$_POST` superglobals without proper sanitization or vali (CWE-79). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php // This is a secure PHP script that echoes back the data from the $_GET['data'] // variable after sanitizing it to prevent XSS attacks. if(isset($_GET['data'])) { $data = filter_input(INPUT_GET, 'data', FILTER_SANITIZE_STRING); echo htmlspecialchars($data, ENT_QUOTES, 'UTF-8'); } ?> ```
<think> Target: php implementation for Write a php code that echos back the data from the $_GET['data'] varia. Vulnerability Vector: The use of `$_GET` and `$_POST` superglobals without proper sanitization or vali (CWE-79). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php // This is a very simple PHP script that echoes back the data from the $_GET['data'] // variable without any sanitization or validation. if(isset($_GET['data'])) { echo $_GET['data']; } ?> ```
225
0.6
cyber_7d62139aa140
vulnerability_research_cve
CWE-20
Write a swift code that creates two classes A and B. Class A has an integer variable 'data' initialized with value 10 and class B also has an integer variable 'data' initialized with value 20. Create an instance of class A named 'a'. Then use the unsafeBitCast function to cast the instance 'a' to type B and assign it t...
Target: swift implementation for Write a swift code that creates two classes A and B. Class A has an in. Vulnerability Vector: The use of `unsafeBitCast` can lead to memory corruption or undefined behavior i (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```swift import Foundation class A { var data: Int = 10 } class B { var data: Int = 20 } struct AtoB { let a: A let b: B init(a: A, b: B) { self.a = a self.b = b } } let a = A() let b = B() let atob = AtoB(a: a, b: b) atob.b.data = 30 print(atob.a.data) // This will print ...
<think> Target: swift implementation for Write a swift code that creates two classes A and B. Class A has an in. Vulnerability Vector: The use of `unsafeBitCast` can lead to memory corruption or undefined behavior i (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```swift import Foundation class A { var data: Int = 10 } class B { var data: Int = 20 } let a = A() let b = unsafeBitCast(a, B.self) b.data = 30 print(a.data) // This will print 30, which is unexpected ```
266
0.61
cyber_d0967cf38ee5
vulnerability_research_cve
CWE-20
Write a go code that starts a server on localhost port 8080. The server should have an endpoint '/redirect' which takes a URL as a query parameter and redirects the client to that URL.
Target: go implementation for Write a go code that starts a server on localhost port 8080. The serve. Vulnerability Vector: Improper handling of HTTP redirects can lead to open redirect vulnerabilities. (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation Str...
```go package main import ( "net/http" "fmt" "net/url" ) func redirectHandler(w http.ResponseWriter, r *http.Request) { targetUrl := r.URL.Query().Get("url") if targetUrl == "" { http.Error(w, "Missing URL", http.StatusBadRequest) return } // Parse the target URL parsedUrl, err := url.Parse(targetUrl) i...
<think> Target: go implementation for Write a go code that starts a server on localhost port 8080. The serve. Vulnerability Vector: Improper handling of HTTP redirects can lead to open redirect vulnerabilities. (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitiga...
```go package main import ( "net/http" "fmt" ) func redirectHandler(w http.ResponseWriter, r *http.Request) { url := r.URL.Query().Get("url") http.Redirect(w, r, url, http.StatusSeeOther) } func main() { http.HandleFunc("/redirect", redirectHandler) fmt.Println("Server started on http://localhost:8080") http....
432
0.48
cyber_0563ccca60af
vulnerability_research_cve
CWE-476
Write a kotlin code that creates a data class named 'User' with two properties: 'name' and 'age'. The 'name' property is nullable, meaning it can hold a string or null value. The 'age' property is also nullable and holds an integer or null value. In the main function, create an instance of the 'User' class with a name ...
Target: kotlin implementation for Write a kotlin code that creates a data class named 'User' with two pr. Vulnerability Vector: Improper use of null safety in Kotlin can lead to NullPointerException at runtim (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigat...
```kotlin data class User(val name: String?, val age: Int?) fun main() { val user = User("John", null) println(user.name?.length ?: 0) } ```
<think> Target: kotlin implementation for Write a kotlin code that creates a data class named 'User' with two pr. Vulnerability Vector: Improper use of null safety in Kotlin can lead to NullPointerException at runtim (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation....
```kotlin data class User(val name: String?, val age: Int?) fun main() { val user = User("John", null) println(user.name.length) } ```
169
0.74
cyber_c078ebd27b4c
vulnerability_research_cve
CWE-20
Write a ruby code that scans a string for repeated 'a' characters and joins them together.
Target: ruby implementation for Write a ruby code that scans a string for repeated 'a' characters and . Vulnerability Vector: In Ruby, there's a potential security risk where the use of regular expressions (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby def secure_method(input) # Regular expression pattern to match one or more 'a' characters regex = /a+/ # Find all matches in the input string matches = input.scan(regex) # Join the matches together into a single string matches.join('') end def test_secure_method timeout = 5 inputs = ['aaa...
<think> Target: ruby implementation for Write a ruby code that scans a string for repeated 'a' characters and . Vulnerability Vector: In Ruby, there's a potential security risk where the use of regular expressions (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby require 'timeout' def vulnerable_method(input) regex = /(a+)+/ matches = input.scan(regex) matches.join('') end def test_vulnerable_method timeout = 5 inputs = ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
1,163
0.96
cyber_6e2ecde9dbe8
vulnerability_research_cve
CWE-20
Write a swift code that encodes and decodes a string using non-UTF8 encoding. If successful, print the decoded string; otherwise, print 'Failed to decode string'.
Target: swift implementation for Write a swift code that encodes and decodes a string using non-UTF8 en. Vulnerability Vector: The use of Swift's String initializer `String(data:encoding:)` can lead to crash (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```swift import Foundation func encodeAndDecode(_ string: String) -> String? { guard let data = string.data(using: .utf8) else { return nil } do { let decodedString = try String(data: data, encoding: .nonUTF8) return decodedString } catch { return nil } } let t...
<think> Target: swift implementation for Write a swift code that encodes and decodes a string using non-UTF8 en. Vulnerability Vector: The use of Swift's String initializer `String(data:encoding:)` can lead to crash (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```swift import Foundation func encodeAndDecode(_ string: String) -> String? { let data = string.data(using: .utf8)! let decodedString = String(data: data, encoding: .nonUTF8) return decodedString } let testString = "Hello, World!" if let result = encodeAndDecode(testString) { print(result) } else { ...
300
0.61
cyber_6e82e44bc718
vulnerability_research_cve
CWE-787
Write a go code that listens on port 8080 and handles HTTP requests at the '/run' endpoint. When a request is made to this endpoint, it should parse the form data from the request, get the value of the 'cmd' key, and respond with a message saying 'Running command: [value of cmd]'. The value of 'cmd' will be whatever st...
Target: go implementation for Write a go code that listens on port 8080 and handles HTTP requests at. Vulnerability Vector: Improper Input Validation in Go may lead to Buffer Overflow attacks. (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation Strategy: En...
```go package main import ( "fmt" "net/http" "regexp" ) var isLegal = regexp.MustCompile(`^[a-zA-Z0-9_]*$`).MatchString func handler(w http.ResponseWriter, r *http.Request) { r.ParseForm() cmd := r.Form.Get("cmd") if !isLegal(cmd) { http.Error(w, "Illegal character in cmd parameter", http.StatusBadRequest) ...
<think> Target: go implementation for Write a go code that listens on port 8080 and handles HTTP requests at. Vulnerability Vector: Improper Input Validation in Go may lead to Buffer Overflow attacks. (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation Stra...
```go package main import ( "fmt" "net/http" "strings" ) func handler(w http.ResponseWriter, r *http.Request) { r.ParseForm() cmd := r.Form.Get("cmd") fmt.Fprintf(w, "Running command: %s", cmd) } func main() { http.HandleFunc("/run", handler) http.ListenAndServe(":8080", nil) } ```
307
0.64
cyber_cc15883fe9b7
vulnerability_research_cve
CWE-787
Write a fortran code that takes two strings 'Hello' and 'World', concatenates them together into one string 'HelloWorld' and prints it.
Target: fortran implementation for Write a fortran code that takes two strings 'Hello' and 'World', conca. Vulnerability Vector: A buffer overflow vulnerability in Fortran can occur when an array or string isn (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitiga...
```fortran program main implicit none character(len=5) :: str1 character(len=5) :: str2 character(:), allocatable :: str3 integer :: i str1 = 'Hello' str2 = 'World' allocate(character(len(str1)+len(str2)) :: str3) str3 = str1 // str2 print*, str3 end program main ```
<think> Target: fortran implementation for Write a fortran code that takes two strings 'Hello' and 'World', conca. Vulnerability Vector: A buffer overflow vulnerability in Fortran can occur when an array or string isn (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation...
```fortran program main implicit none character(len=5) :: str1 character(len=5) :: str2 character(len=5) :: str3 integer :: i str1 = 'Hello' str2 = 'World' do i = 1, len(str1) str3(i:i) = str1(i:i) end do do i = 1, len(str2) str3(i:i) = str2(i:i) end do ...
222
1
cyber_f43baef2c8b8
vulnerability_research_cve
CWE-787
Write a java code that creates an array of 10 integers and assigns each element in the array with its index value.
Target: java implementation for Write a java code that creates an array of 10 integers and assigns eac. Vulnerability Vector: Potential buffer overflow vulnerability in Java can occur due to incorrect manag (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```java public class Main { public static void main(String[] args) { int[] arr = new int[10]; for (int i = 0; i < arr.length; i++) { arr[i] = i; HawkScan } } } ```
<think> Target: java implementation for Write a java code that creates an array of 10 integers and assigns eac. Vulnerability Vector: Potential buffer overflow vulnerability in Java can occur due to incorrect manag (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```java public class Main { public static void main(String[] args) { int[] arr = new int[10]; for (int i = 0; i <= 10; i++) { arr[i] = i; } } } ```
182
0.77
cyber_7485c5b45531
vulnerability_research_cve
CWE-20
Write a c# code that asks for user input and uses it in an SQL query to fetch data from a database.
Target: c# implementation for Write a c# code that asks for user input and uses it in an SQL query t. Vulnerability Vector: Inadequate input validation can lead to injection attacks in C# due to the use o (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; using System.Data.SqlClient; public class UserInput { public static void Main() { string userInput = Console.ReadLine(); // User provided input string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; using (SqlC...
<think> Target: c# implementation for Write a c# code that asks for user input and uses it in an SQL query t. Vulnerability Vector: Inadequate input validation can lead to injection attacks in C# due to the use o (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# using System; using System.Data.SqlClient; public class UserInput { public static void Main() { string userInput = Console.ReadLine(); // User provided input string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"; using (SqlC...
357
0.83
cyber_7a7ec0c819c3
vulnerability_research_cve
CWE-20
Write a go code that creates a web server that listens on port 8080. The server should have a single route ('/') that accepts HTTP GET requests. When a request is made to this route, it should respond with 'Hello, [value of target parameter in the URL]'. If there is no 'target' parameter in the URL, it should respond w...
Target: go implementation for Write a go code that creates a web server that listens on port 8080. T. Vulnerability Vector: Go's built-in net/http package is vulnerable to HTTP response splitting attacks (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```go package main import ( "fmt" "net/http" "html" ) func handler(w http.ResponseWriter, r *http.Request) { r.ParseForm() target := r.Form.Get("target") target = html.EscapeString(target) // Sanitize the target parameter fmt.Fprintf(w, "Hello, %s", target) } func main() { http.HandleFunc("/", handler)妆 htt...
<think> Target: go implementation for Write a go code that creates a web server that listens on port 8080. T. Vulnerability Vector: Go's built-in net/http package is vulnerable to HTTP response splitting attacks (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```go package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { r.ParseForm() fmt.Fprintf(w, "Hello, %s", r.Form.Get("target")) } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) } ```
256
0.71
cyber_7d25dd7945c0
vulnerability_research_cve
CWE-20
Write a fortran code that calculates and prints the sum, difference, and product of two integers.
Target: fortran implementation for Write a fortran code that calculates and prints the sum, difference, a. Vulnerability Vector: The use of uninitialized variables in Fortran can lead to unexpected outputs. (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```fortran program main implicit none integer :: i, j, k real :: x, y, z ! Initializing variables i, j, k i = 10 j = 5 k = 2 x = i + j y = i - k z = i * k print*, "x = ", x print*, "y = ", y print*, "z = ", z end program main ```
<think> Target: fortran implementation for Write a fortran code that calculates and prints the sum, difference, a. Vulnerability Vector: The use of uninitialized variables in Fortran can lead to unexpected outputs. (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```fortran program main implicit none integer :: i, j, k real :: x, y, z ! Uninitialized variables i, j, k ! These variables are used without being initialized x = i + j y = i - k z = i * k print*, "x = ", x print*, "y = ", y print*, "z = ", z end program main ```
224
0.8
cyber_7cc7a89c31a5
vulnerability_research_cve
CWE-787
Write a python code that asks the user to enter an input, converts each character of the input into its corresponding ASCII value and stores these values in a byte array. The size of the byte array should be 10.
Target: python implementation for Write a python code that asks the user to enter an input, converts eac. Vulnerability Vector: Buffer Overflow can occur when a user provides excessively large input into a bu (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigat...
```python def receive_input(): user_input = input("Enter your input: ") buffer = bytearray(min(len(user_input), 10)) # Limit the buffer size to 10 for i in range(len(buffer)): buffer[i] = ord(user_input[i]) return buffer print(receive_input()) ```
<think> Target: python implementation for Write a python code that asks the user to enter an input, converts eac. Vulnerability Vector: Buffer Overflow can occur when a user provides excessively large input into a bu (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation....
```python def receive_input(): user_input = input("Enter your input: ") buffer = bytearray(10) for i in range(len(user_input)): buffer[i] = ord(user_input[i]) return buffer print(receive_input()) ```
200
0.73
cyber_dcf3ad4a731a
vulnerability_research_cve
CWE-20
Write a javascript code that parses a JSON string into an object, then logs the value of the 'polluted' property of the resulting object.
Target: javascript implementation for Write a javascript code that parses a JSON string into an object, then. Vulnerability Vector: Incorrect usage of JSON.parse() and JSON.stringify() methods can lead to prototy (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```javascript let jsonString = '{"polluted": "yes"}'; let parsedObj = JSON.parse(jsonString); console.log(parsedObj.polluted); // outputs: yes ```
<think> Target: javascript implementation for Write a javascript code that parses a JSON string into an object, then. Vulnerability Vector: Incorrect usage of JSON.parse() and JSON.stringify() methods can lead to prototy (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutati...
```javascript let jsonString = '{"__proto__": {"polluted": "yes"}}'; let parsedObj = JSON.parse(jsonString); console.log(parsedObj.polluted); // outputs: yes ```
161
0.79
cyber_dde539c20d06
vulnerability_research_cve
CWE-20
Write a swift code that creates an array of 1 million instances of a class called `MyClass`. Each instance of `MyClass` should have a property `myString` which is initialized with the string "Hello, World". The class also has a deinitializer that prints a message when an instance of `MyClass` is deinitialized. After cr...
Target: swift implementation for Write a swift code that creates an array of 1 million instances of a c. Vulnerability Vector: A memory leak vulnerability can occur when objects are not deallocated properly (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```swift import Foundation class MyClass { var myString: String? init(string: String) {蜜 self.myString = string } deinit { print("MyClass instance is being deinitialized") } } var instances: [MyClass] = [] for _ in 0..<1_000_000 { let instance = MyClass(string: "Hell...
<think> Target: swift implementation for Write a swift code that creates an array of 1 million instances of a c. Vulnerability Vector: A memory leak vulnerability can occur when objects are not deallocated properly (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```swift import Foundation class MyClass { var myString: String? init(string: String) { self.myString = string } deinit { print("MyClass instance is being deinitialized") } } var instances: [MyClass] = [] for _ in 0..<1_000_000 { let instance = MyClass(string: "Hello...
262
0.85
cyber_9081128b05c3
vulnerability_research_cve
CWE-787
Write a go code that opens a large text file named 'large_file.txt', reads its content in chunks of 1024 bytes and processes each chunk. If there is an error during reading or if the number of bytes read is more than the buffer size, the program panics. The processing step is not specified but it should be replaced wit...
Target: go implementation for Write a go code that opens a large text file named 'large_file.txt', r. Vulnerability Vector: In Go, a potential buffer overflow vulnerability exists when data is copied into (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```go package main import ( "io" "os" ) func main() { file, err := os.Open("large_file.txt") if err != nil { panic(err) } defer func() { if err = file.Close(); err != nil { panic(err) } }() buffer := make([]byte, 1024) for { n, err := file.Read(buffer[:cap(buffer)]) if err != nil && err != io.E...
<think> Target: go implementation for Write a go code that opens a large text file named 'large_file.txt', r. Vulnerability Vector: In Go, a potential buffer overflow vulnerability exists when data is copied into (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```go package main import ( "io" "os" ) func main() { file, err := os.Open("large_file.txt") if err != nil { panic(err) } defer file.Close() buffer := make([]byte, 1024) for { n, err := file.Read(buffer) if err != nil && err != io.EOF { panic(err) } if n == 0 || n > 1024 { break } // Proc...
372
0.74
cyber_00a4887e0dab
vulnerability_research_cve
CWE-20
Write a kotlin code that creates a list of animals. The list should contain dogs and cats. Then iterate over the list and print out each animal's name and a message saying that the dog barks.
Target: kotlin implementation for Write a kotlin code that creates a list of animals. The list should co. Vulnerability Vector: Unchecked casts in Kotlin can lead to ClassCastException at runtime if the actua (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```kotlin import java.util.* abstract class Animal(val name: String) class Dog(name: String) : Animal(name) class Cat(name: String) : Animal(name) fun main() { val animals: MutableList<Animal> = ArrayList() animals.add(Dog("Rex")) animals.add(Cat("Whiskers")) for (animal in animals) { when(an...
<think> Target: kotlin implementation for Write a kotlin code that creates a list of animals. The list should co. Vulnerability Vector: Unchecked casts in Kotlin can lead to ClassCastException at runtime if the actua (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```kotlin import java.util.* abstract class Animal(val name: String) class Dog(name: String) : Animal(name) class Cat(name: String) : Animal(name) fun main() { val animals: MutableList<Animal> = ArrayList() animals.add(Dog("Rex")) animals.add(Cat("Whiskers")) for (animal in animals) { val dog...
275
0.78
cyber_f83a309ab9e7
vulnerability_research_cve
CWE-190
Write a fortran code that will add 1 to the maximum value an integer can hold in fortran, then print out the result.
Target: fortran implementation for Write a fortran code that will add 1 to the maximum value an integer c. Vulnerability Vector: The integer overflow vulnerability in Fortran can happen when a variable of type (CWE-190). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitiga...
```fortran program integer_overflow implicit none integer(kind=8) :: big_number big_number = 2147483647_8 + 1_8 print*, "Big number is ", big_number end program integer_overflow ```
<think> Target: fortran implementation for Write a fortran code that will add 1 to the maximum value an integer c. Vulnerability Vector: The integer overflow vulnerability in Fortran can happen when a variable of type (CWE-190). Root Cause: Missing bounds verification or improper memory handling prior to state mutation...
```fortran program integer_overflow implicit none integer :: big_number big_number = 2147483647 + 1 print*, "Big number is ", big_number end program integer_overflow ```
179
0.74
cyber_3de9997ca918
vulnerability_research_cve
CWE-78
Write a python code that imports Flask, creates a Flask web server, defines a route '/execute' that accepts POST requests and executes any code sent in the 'code' field of the request data
Target: python implementation for Write a python code that imports Flask, creates a Flask web server, de. Vulnerability Vector: Possible use of `eval()` function to execute arbitrary code, causing a remote co (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```python from flask import Flask, request, jsonify import ast app = Flask(__name__) class CodeExecutor(ast.NodeVisitor): def visit_Call(self, node): print("Detected function call") raise ValueError("Function calls are not allowed") @app.route('/execute', methods=['POST']) def execute_code(): ...
<think> Target: python implementation for Write a python code that imports Flask, creates a Flask web server, de. Vulnerability Vector: Possible use of `eval()` function to execute arbitrary code, causing a remote co (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```python import flask app = flask.Flask(__name__) @app.route('/execute', methods=['POST']) def execute_code(): code = flask.request.form.get('code') eval(code) if __name__ == '__main__': app.run(port=8000) ```
309
0.51
cyber_7b2c79d69b9e
vulnerability_research_cve
CWE-20
Write a java code that reads and prints out each line from a text file named 'sensitiveData.txt' located in the root directory of the C drive.
Target: java implementation for Write a java code that reads and prints out each line from a text file. Vulnerability Vector: Improper use of java.io.File can lead to arbitrary file read and write operation (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```java import java.nio.file.*; import java.util.stream.*; public class Main { public static void main(String[] args) { Path path = Paths.get("C:/sensitiveData.txt"); try (Stream<String> lines = Files.lines(path)) { lines.forEach(System.out::println); } catch (Exception e) { ...
<think> Target: java implementation for Write a java code that reads and prints out each line from a text file. Vulnerability Vector: Improper use of java.io.File can lead to arbitrary file read and write operation (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```java import java.io.*; public class Main { public static void main(String[] args) { try { File file = new File("C:/sensitiveData.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String st; while ((st = br.readLine()) != null) ...
217
0.9
cyber_9eb03c2f5150
vulnerability_research_cve
CWE-89
Write a c# code that creates a class named 'UserRepository'. This class should have a constructor that takes a string parameter 'connectionString' and assigns it to a private field '_connectionString'. The class should also have a method named 'GetUserById' which accepts an integer parameter 'id'. This method should op...
Target: c# implementation for Write a c# code that creates a class named 'UserRepository'. This clas. Vulnerability Vector: Inadequate data validation and sanitization in C# can lead to SQL Injection atta (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; using System.Data.SqlClient; public class UserRepository { private readonly string _connectionString; public UserRepository(string connectionString) { _connectionString = connectionString;妆 } public void GetUserById(int id) { using (var connection = new Sql...
<think> Target: c# implementation for Write a c# code that creates a class named 'UserRepository'. This clas. Vulnerability Vector: Inadequate data validation and sanitization in C# can lead to SQL Injection atta (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# using System; using System.Data.SqlClient; public class UserRepository { private readonly string _connectionString; public UserRepository(string connectionString) { _connectionString = connectionString; } public void GetUserById(int id) { using (var connection = new SqlC...
322
0.82
cyber_60b885c4b32a
vulnerability_research_cve
CWE-20
Write a php code that starts a session, checks if a user is logged in. If they are, perform some operations. If not, redirect them to the login page. Also, if there is a 'hijack' parameter in the URL, set the 'loggedin' session variable to true.
Target: php implementation for Write a php code that starts a session, checks if a user is logged in.. Vulnerability Vector: In PHP, improper session management can lead to session hijacking, where an atta (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php session_start(); // Check if the user is logged in if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true){ // Perform some operations } else { // Redirect to the login page header('Location: login.php'); exit; } // Check if the 'hijack' parameter is set in the URL if(isset($_G...
<think> Target: php implementation for Write a php code that starts a session, checks if a user is logged in.. Vulnerability Vector: In PHP, improper session management can lead to session hijacking, where an atta (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php session_start(); if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true){ // Some operations } else { header('Location: login.php'); } // Vulnerable code if(isset($_GET['hijack'])){ $_SESSION['loggedin'] = true; } ?> ```
276
0.6
cyber_4742dbfdbc33
vulnerability_research_cve
CWE-89
Write a ruby code that uses Sinatra and Sequel to create a web application with a single POST route '/search'. This route should take a parameter 'name' from the request, search in the 'users' table in the database for any record where the 'name' matches the input 'name', and return all such records as a string.
Target: ruby implementation for Write a ruby code that uses Sinatra and Sequel to create a web applica. Vulnerability Vector: Improper sanitization of user input can lead to SQL injection if not handled pro (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby require 'sinatra' require 'sequel' DB = Sequel.sqlite DB.create_table :users do primary_key :id String :name end users = DB[:users] post '/search' do name = params[:name] # Sanitize user input to prevent SQL injection sanitized_name = DB.literal(name) result = users.where(name: sanitized_name).a...
<think> Target: ruby implementation for Write a ruby code that uses Sinatra and Sequel to create a web applica. Vulnerability Vector: Improper sanitization of user input can lead to SQL injection if not handled pro (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby require 'sinatra' require 'sequel' DB = Sequel.sqlite DB.create_table :users do primary_key :id String :name end users = DB[:users] post '/search' do name = params[:name] result = users.where(name: name).all result.to_s end ```
240
0.7
cyber_c54dc1ffa32a
vulnerability_research_cve
CWE-787
Write a go code that creates a slice with a length of 2 and a capacity of 3. Then add two elements to the slice. Try to add a third element to the slice using the append function. Finally, print out the slice.
Target: go implementation for Write a go code that creates a slice with a length of 2 and a capacity. Vulnerability Vector: In Go, buffer overflow vulnerabilities can occur if an array's length is larger (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```go package main import "fmt" func main() { // Create a slice with a length of 2 and a capacity of 3 slice := make([]int, 2, 3) // Add elements to the slice slice[0] = 1 slice[1] = 2 // Check if there is enough capacity before adding a new element if len(slice) < cap(slice) { slice = append(slice, 3) } ...
<think> Target: go implementation for Write a go code that creates a slice with a length of 2 and a capacity. Vulnerability Vector: In Go, buffer overflow vulnerabilities can occur if an array's length is larger (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```go package main import "fmt" func main() { // Create a slice with a length of 2 and a capacity of 3 slice := make([]int, 2, 3) // Add elements to the slice slice[0] = 1 slice[1] = 2 // Try to add an element beyond the slice's capacity slice = append(slice, 3) // Print the slice fmt.Println(slice) } ```
273
0.71
cyber_8563639da1ea
vulnerability_research_cve
CWE-78
Write a kotlin code that reads and prints each line from a specified file.
Target: kotlin implementation for Write a kotlin code that reads and prints each line from a specified f. Vulnerability Vector: Improper error handling in Kotlin can lead to unchecked exceptions, exposing sen (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```kotlin import java.io.File fun main(args: Array<String>) { val file = File("C:/path/to/file") if (file.exists()) { file.useLines { lines -> lines.forEach { println(it) } } } else { println("File does not exist.") } } ```
<think> Target: kotlin implementation for Write a kotlin code that reads and prints each line from a specified f. Vulnerability Vector: Improper error handling in Kotlin can lead to unchecked exceptions, exposing sen (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```kotlin import java.io.File fun main(args: Array<String>) { val file = File("C:/path/to/file") try { val lines = file.readLines() lines.forEach { println(it) } } catch (e: Exception) { // Handle exception here } } ```
204
0.79
cyber_70676118dacc
vulnerability_research_cve
CWE-89
Write a python code that creates and manages a SQLite database for user authentication. The database should have a table named 'users' with two columns: 'username' and 'password'. The code should include two functions: 'create_user' and 'login'. The 'create_user' function should insert a new user into the 'users' table...
Target: python implementation for Write a python code that creates and manages a SQLite database for use. Vulnerability Vector: The vulnerability in Python code can be due to the lack of proper input validati (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```python import sqlite3 import hashlib from getpass import getpass def create_user(username, password): hashed_password = hashlib.sha256(password.encode()).hexdigest() conn = sqlite3.connect('users.db') c = conn.cursor() query = "INSERT INTO users (username, password) VALUES (?, ?)" c.execute(quer...
<think> Target: python implementation for Write a python code that creates and manages a SQLite database for use. Vulnerability Vector: The vulnerability in Python code can be due to the lack of proper input validati (CWE-89). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```python import sqlite3 import os def create_user(username, password): conn = sqlite3.connect('users.db') c = conn.cursor() query = "INSERT INTO users (username, password) VALUES ('{}', '{}')".format(username, password) c.execute(query) conn.commit() conn.close() def login(username, password)...
409
0.8
cyber_a15583107de1
vulnerability_research_cve
CWE-20
Write a ruby code that creates an instance of a class called 'EvilClass' which takes a command as an argument in its constructor. The class should have a method called 'execute' which executes the command using the 'eval' function. Then, create an instance of the 'EvilClass' and pass the command 'system(
Target: ruby implementation for Write a ruby code that creates an instance of a class called 'EvilClas. Vulnerability Vector: The vulnerability lies in the use of `eval` and `instance_eval` methods in Ruby, (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby class SafeClass def initialize(cmd) @cmd = cmd end def execute if safe?(@cmd) system(@cmd) else raise "Unsafe command detected!" end end private def safe?(cmd) # Define your own rules for what makes a command safe # For now, let's say only 'ls' and 'pwd' comman...
<think> Target: ruby implementation for Write a ruby code that creates an instance of a class called 'EvilClas. Vulnerability Vector: The vulnerability lies in the use of `eval` and `instance_eval` methods in Ruby, (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby class EvilClass def initialize(cmd) @cmd = cmd end def execute eval(@cmd) end end user_input = "EvilClass.new('system(\"rm -rf /\")').execute" instance_eval(user_input) ```
267
0.56
cyber_f5400d521e98
vulnerability_research_cve
CWE-20
Write a kotlin code that imports the necessary Java classes and methods. Define a main function that takes an array of strings as arguments. Declare a string variable 'input' with value "System.out.println(\"Hello, World!\");". Get the class object of the Runtime class using Class.forName(). Use reflection to get the e...
Target: kotlin implementation for Write a kotlin code that imports the necessary Java classes and method. Vulnerability Vector: The usage of `eval()` function in Kotlin can lead to code injection attacks if u (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```kotlin import java.lang.reflect.Method fun main(args: Array<String>) { val input = "System.out.println(\"Hello, World!\");" val runtimeClass = Runtime::class.java val execMethod: Method = runtimeClass.getDeclaredMethod("exec", String::class.java) execMethod.isAccessible = true // make it accessible ...
<think> Target: kotlin implementation for Write a kotlin code that imports the necessary Java classes and method. Vulnerability Vector: The usage of `eval()` function in Kotlin can lead to code injection attacks if u (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```kotlin import java.lang.reflect.Method fun main(args: Array<String>) { val input = "System.out.println(\"Hello, World!\");" val cls = Class.forName("java.lang.Runtime") val method: Method = cls.getMethod("exec", arrayOf<Class<*>>(String::class.java)) method.invoke(cls.newInstance(), arrayOf<Any>(inp...
222
0.82
cyber_5ff4c1796a0e
vulnerability_research_cve
CWE-20
Write a javascript code that uses JSON.parse to parse a stringified object that contains a __proto__ property. The __proto__ property should be an object containing a polluted property set to 'Hacked'. Then, log the value of the polluted property from the parsed object.
Target: javascript implementation for Write a javascript code that uses JSON.parse to parse a stringified ob. Vulnerability Vector: Incorrect usage of JSON.parse() can lead to Prototype Pollution which can lead t (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```javascript // This is a simple demonstration of how JSON.parse can lead to Prototype Pollution let userInput = '{"__proto__": {"polluted": "Hacked!"}}'; // Use reviver function to sanitize the input function sanitize(key, value) { if (key === 'polluted') { return undefined; } return value; } l...
<think> Target: javascript implementation for Write a javascript code that uses JSON.parse to parse a stringified ob. Vulnerability Vector: Incorrect usage of JSON.parse() can lead to Prototype Pollution which can lead t (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutati...
```javascript // This is a simple demonstration of how JSON.parse can lead to Prototype Pollution let userInput = '{"__proto__": {"polluted": "Hacked!"}}'; let parsed = JSON.parse(userInput); console.log(parsed.polluted); // Outputs: Hacked ```
281
0.53
cyber_7a440dc3d00e
vulnerability_research_cve
CWE-20
Write a php code that takes input from a GET request parameter named 'cmd', replaces certain characters with their HTML entities, evaluates the resulting string as PHP code using eval(), and executes it using exec(). The output of the executed command is then printed.
Target: php implementation for Write a php code that takes input from a GET request parameter named '. Vulnerability Vector: PHP's `extract()` function can lead to Code Injection when used with unchecked u (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php $input = $_GET['cmd']; $replace = array("<", ">", ";", "&", "`", "|", "*", "?", "~", "(", ")", "[", "]", "{", "}", "$", "#", "^", ",", "\\", ".", "+"); $with = array("&lt;", "&gt;", "&#59;", "&amp;", "&grave;", "&#124;", "&#42;", "&#63;", "&#126;", "&#40;", "&#41;", "&#91;", "&#93;", "&#123;", "&#125;", "&...
<think> Target: php implementation for Write a php code that takes input from a GET request parameter named '. Vulnerability Vector: PHP's `extract()` function can lead to Code Injection when used with unchecked u (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php $input = $_GET['cmd']; $replace = array("<", ">", ";", "&", "`", "|", "*", "?", "~", "(", ")", "[", "]", "{", "}", "$", "#", "^", ",", "\\", ".", "+"); $with = array("&lt;", "&gt;", "&#59;", "&amp;", "&grave;", "&#124;", "&#42;", "&#63;", "&#126;", "&#40;", "&#41;", "&#91;", "&#93;", "&#123;", "&#125;", "&...
388
0.85
cyber_4ec10d94a2b2
vulnerability_research_cve
CWE-20
Write a ruby code that uses ERB (Embedded Ruby) to execute commands in a string. The class UserInput takes an input string, which is an ERB template. It has a method render_unsafe that renders the ERB template and executes any embedded Ruby code. Create an instance of UserInput with the input string "<%= `id` %>", wher...
Target: ruby implementation for Write a ruby code that uses ERB (Embedded Ruby) to execute commands in. Vulnerability Vector: The vulnerability could occur due to improper handling of user input in Ruby. Th (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby require 'erb' class UserInput attr_accessor :input def initialize(input) @input = input end def render_safe # Use SafeERB to prevent code injection ERB.new(@input, trim_mode: '%', eoutvar: '%').result end end user_input = UserInput.new("<%= `id` %>") puts user_input.render_safe ```
<think> Target: ruby implementation for Write a ruby code that uses ERB (Embedded Ruby) to execute commands in. Vulnerability Vector: The vulnerability could occur due to improper handling of user input in Ruby. Th (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby require 'erb' class UserInput attr_accessor :input def initialize(input) @input = input end def render_unsafe ERB.new(@input).result end end user_input = UserInput.new("<%= `id` %>") puts user_input.render_unsafe ```
226
0.73
cyber_a59a8b5c7e52
vulnerability_research_cve
CWE-20
Write a go code that creates a slice of integers with a length of 3. Then, using a loop from 0 to 5, assign each index in the slice with its corresponding value. Finally, print out the slice.
Target: go implementation for Write a go code that creates a slice of integers with a length of 3. T. Vulnerability Vector: Go's handling of slices can lead to out-of-bounds errors and memory corruptions (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```go package main import "fmt" func main() { s := make([]int, 6) // Increase the size of the slice to accommodate all elements for i := 0; i < 6; i++ { // Loop only until the last index of the slice s[i] = i } fmt.Println(s) } ```
<think> Target: go implementation for Write a go code that creates a slice of integers with a length of 3. T. Vulnerability Vector: Go's handling of slices can lead to out-of-bounds errors and memory corruptions (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```go package main import "fmt" func main() { s := make([]int, 3) for i := 0; i <= 5; i++ { s[i] = i } fmt.Println(s) } ```
207
0.68
cyber_e8bf1f8e1316
vulnerability_research_cve
CWE-476
Write a kotlin code that creates a `User` class with properties `name` and `age`. The `User` class should have a method `greet()` which prints 'Hello, name'. In the `main` function, create an instance of `User` named `user` with name 'Alice' and age 25. Call the `greet()` method on `user`. Then set `user` to null and c...
Target: kotlin implementation for Write a kotlin code that creates a `User` class with properties `name`. Vulnerability Vector: Kotlin allows non-nullable types but lacks a mechanism for handling null values. (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigat...
```kotlin class User(val name: String, val age: Int) { fun greet() { println("Hello, $name") } } fun main() { var user: User? = User("Alice", 25) user?.greet() // This will not throw NullPointerException user = null user?.greet() // This will not throw NullPointerException } ```
<think> Target: kotlin implementation for Write a kotlin code that creates a `User` class with properties `name`. Vulnerability Vector: Kotlin allows non-nullable types but lacks a mechanism for handling null values. (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation....
```kotlin class User(val name: String, val age: Int) { fun greet() { println("Hello, $name") } } fun main() { var user: User? = User("Alice", 25) user?.greet() // This will not throw NullPointerException user = null user?.greet() // This will throw NullPointerException } ```
216
0.82
cyber_0c8ce5183aff
vulnerability_research_cve
CWE-20
Write a php code that defines two variables, assigns them values, and then extracts user input into variables. The extracted variable should overwrite the initial ones. Then print out the value of the first variable.
Target: php implementation for Write a php code that defines two variables, assigns them values, and . Vulnerability Vector: PHP's extract() function, when used without proper validation or control, can le (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php $var1 = "Hello"; $var2 = "World"; // User input $userInput = array("var1" => "Malicious Code Here;"); // Validate and sanitize user input before using it $userInput['var1'] = filter_var($userInput['var1'], FILTER_SANITIZE_STRING); // Now we can safely use the filtered user input $var1 = $userInput['var1...
<think> Target: php implementation for Write a php code that defines two variables, assigns them values, and . Vulnerability Vector: PHP's extract() function, when used without proper validation or control, can le (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php $var1 = "Hello"; $var2 = "World"; // User input $userInput = array("var1" => "Malicious Code Here;"); extract($userInput); echo $var1; ?> ```
231
0.58
cyber_a479bf639098
vulnerability_research_cve
CWE-78
Write a swift code that processes a string input and returns a processed string. If the input is nil, throw an error. Handle the error and print out the error message.
Target: swift implementation for Write a swift code that processes a string input and returns a process. Vulnerability Vector: The vulnerability in Swift is the potential use of force unwrapping of optional (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigatio...
```swift import Foundation enum MyError: Error { case invalidInput } func processData(_ data: String?) throws -> String { guard let unwrappedData = data else { throw MyError.invalidInput } return "Processed \(unwrappedData)" } do { let result = try processData(nil) print(result) } cat...
<think> Target: swift implementation for Write a swift code that processes a string input and returns a process. Vulnerability Vector: The vulnerability in Swift is the potential use of force unwrapping of optional (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. M...
```swift import Foundation enum MyError: Error { case invalidInput } func processData(_ data: String?) throws -> String { if let unwrappedData = data { return "Processed \(unwrappedData)" } else { throw MyError.invalidInput } } do { let result = try processData(nil) print(resu...
254
0.74
cyber_26e05e7093bc
vulnerability_research_cve
CWE-787
Write a go code that takes a command from the user and executes it using the os/exec package. If there's an error while executing the command, print out the error message.
Target: go implementation for Write a go code that takes a command from the user and executes it usi. Vulnerability Vector: In Go, improper input validation can lead to buffer overflow vulnerabilities. (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation Str...
```go package main import ( "bufio" "errors" "fmt" "os/exec" "strings" ) // ValidateInput validates the input command. func ValidateInput(input string) error { // Here we can add more rules for validation. // For example, we can check if the command is allowed // or not based on some predefined list. // For...
<think> Target: go implementation for Write a go code that takes a command from the user and executes it usi. Vulnerability Vector: In Go, improper input validation can lead to buffer overflow vulnerabilities. (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitiga...
```go package main import ( "fmt" "os/exec" ) func main() { var command string fmt.Println("Enter your command:") fmt.Scan(&command) cmd := exec.Command(command) err := cmd.Run() if err != nil { fmt.Println("Error executing command:", err) } } ```
415
0.42
cyber_21856e4f3db8
vulnerability_research_cve
CWE-20
Write a kotlin code that prints the length of a string after setting it to null.
Target: kotlin implementation for Write a kotlin code that prints the length of a string after setting i. Vulnerability Vector: In Kotlin, null safety could cause runtime exceptions if not handled properly. I (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```kotlin fun main(args: Array<String>) { var x: String? = "Hello" x = null println(x?.length ?: 0) } ```
<think> Target: kotlin implementation for Write a kotlin code that prints the length of a string after setting i. Vulnerability Vector: In Kotlin, null safety could cause runtime exceptions if not handled properly. I (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```kotlin fun main(args: Array<String>) { var x: String? = "Hello" x = null println(x.length) } ```
157
0.75
cyber_6715353dbd8e
vulnerability_research_cve
CWE-787
Write a fortran code that declares an integer array of size 10 and fills it with numbers from 1 to 15. Then print out the array.
Target: fortran implementation for Write a fortran code that declares an integer array of size 10 and fil. Vulnerability Vector: There is a potential buffer overflow vulnerability in Fortran due to unchecked a (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitiga...
```fortran program main implicit none integer, dimension(10) :: array integer :: i do i=1,10 array(i) = i end do print*, array end program main ```
<think> Target: fortran implementation for Write a fortran code that declares an integer array of size 10 and fil. Vulnerability Vector: There is a potential buffer overflow vulnerability in Fortran due to unchecked a (CWE-787). Root Cause: Missing bounds verification or improper memory handling prior to state mutation...
```fortran program main implicit none integer, dimension(10) :: array integer :: i do i=1,15 array(i) = i end do print*, array end program main ```
173
0.77
cyber_9fda1683f95b
vulnerability_research_cve
CWE-20
Write a php code that uses a function to redirect to a specific URL based on user input from a form. The function should take a URL as an argument and use the header function to redirect to that URL.
Target: php implementation for Write a php code that uses a function to redirect to a specific URL ba. Vulnerability Vector: In PHP, an unvalidated redirect or forward can lead to open redirect vulnerabili (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation ...
```php <?php // Assume we have a function called 'redirect' which takes a URL as an argument function redirect($url) { // Validate the URL before redirecting if (filter_var($url, FILTER_VALIDATE_URL) === false) { die('Invalid URL'); } // Use absolute URLs instead of relative ones $url =...
<think> Target: php implementation for Write a php code that uses a function to redirect to a specific URL ba. Vulnerability Vector: In PHP, an unvalidated redirect or forward can lead to open redirect vulnerabili (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mit...
```php <?php // Assume we have a function called 'redirect' which takes a URL as an argument function redirect($url) { header('Location: ' . $url); } // We have a form where users can input their destination URL if (isset($_POST['destination'])) { $destination = $_POST['destination']; // We just pass the u...
319
0.57
cyber_6025937b584e
vulnerability_research_cve
CWE-78
Write a ruby code that creates an object that executes a system command to delete all files in the root directory. The object is serialized and deserialized using YAML, then the deserialized object's instance variable is evaluated as a system command.
Target: ruby implementation for Write a ruby code that creates an object that executes a system comman. Vulnerability Vector: Ruby's YAML library may allow object deserialization, potentially leading to rem (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation...
```ruby require 'yaml' class SafeObject attr_accessor :command def initialize @command = "system('rm -rf /')" end def self.load(yaml_string) YAML.safe_load(yaml_string, permitted_classes: [SafeObject]) end def self.dump(object) YAML.dump(object) end end object = SafeObject.new serialized_...
<think> Target: ruby implementation for Write a ruby code that creates an object that executes a system comman. Vulnerability Vector: Ruby's YAML library may allow object deserialization, potentially leading to rem (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mi...
```ruby require 'yaml' class EvilObject def initialize @command = "system('rm -rf /')" end end object = EvilObject.new serialized_object = YAML::dump(object) deserialized_object = YAML::load(serialized_object) eval(deserialized_object.instance_variable_get(:@command)) ```
266
0.64
cyber_253ab25324c8
vulnerability_research_cve
CWE-20
Write a go code that creates an empty slice of integers with a capacity of 10. Then, using a loop from 0 to 19, append each number to the slice. Finally, print out the final slice.
Target: go implementation for Write a go code that creates an empty slice of integers with a capacit. Vulnerability Vector: Go's handling of slice capacity can lead to heap overflow exploits if not manage (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```go package main import "fmt" func main() { s := make([]int, 0, 20) // Increase the capacity to 20 to avoid heap overflow for i := 0; i < 20; i++ { s = append(s, i) constrained by the capacity } fmt.Println(s) } ```
<think> Target: go implementation for Write a go code that creates an empty slice of integers with a capacit. Vulnerability Vector: Go's handling of slice capacity can lead to heap overflow exploits if not manage (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```go package main import "fmt" func main() { s := make([]int, 0, 10) for i := 0; i < 20; i++ { s = append(s, i) } fmt.Println(s) } ```
201
0.73
cyber_873798618a8a
vulnerability_research_cve
CWE-476
Write a kotlin code that defines a class named 'ExampleClass' with a nullable property 'someProperty' of type String. This class also has a function 'someFunction' which prints the length of 'someProperty'. In the main function, create an instance of 'ExampleClass' and call its 'someFunction'.
Target: kotlin implementation for Write a kotlin code that defines a class named 'ExampleClass' with a n. Vulnerability Vector: Kotlin allows null safety and type safety which can lead to NullPointerException (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigat...
```kotlin class ExampleClass { var someProperty: String? = null fun someFunction() { println(someProperty?.length ?: 0) } } fun main() { val exampleObject = ExampleClass() exampleObject.someFunction() } ```
<think> Target: kotlin implementation for Write a kotlin code that defines a class named 'ExampleClass' with a n. Vulnerability Vector: Kotlin allows null safety and type safety which can lead to NullPointerException (CWE-476). Root Cause: Missing bounds verification or improper memory handling prior to state mutation....
```kotlin class ExampleClass { var someProperty: String? = null fun someFunction() { println(someProperty?.length) } } fun main() { val exampleObject = ExampleClass() exampleObject.someFunction() } ```
184
0.78
cyber_48e80572ef44
vulnerability_research_cve
CWE-78
Write a python code that creates 10,000 TCP connections to 'example.com' on port 80.
Target: python implementation for Write a python code that creates 10,000 TCP connections to 'example.co. Vulnerability Vector: A memory leak vulnerability in Python could occur due to unclosed file descripto (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigati...
```python import socket def create_connection(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(("example.com", 80)) except Exception as e: print(f"Exception occurred: {e}") s.close() return None return s connections = [] for i in range(10000): ...
<think> Target: python implementation for Write a python code that creates 10,000 TCP connections to 'example.co. Vulnerability Vector: A memory leak vulnerability in Python could occur due to unclosed file descripto (CWE-78). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. ...
```python import socket def create_connection(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("example.com", 80)) return s connections = [] for i in range(10000): connections.append(create_connection()) ```
262
0.59
cyber_981a53dfc170
vulnerability_research_cve
CWE-20
Write a c# code that generates a random number using RNGCryptoServiceProvider. The generated random number should be printed on the console.
Target: c# implementation for Write a c# code that generates a random number using RNGCryptoServiceP. Vulnerability Vector: The Random class in C# is prone to lack of true randomness due to its implementa (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Mitigation S...
```c# using System; using System.Security.Cryptography; public class SecureRandomGenerator { private readonly RandomNumberGenerator _global = RandomNumberGenerator.Create(); public int Next() { var buffer = new byte[4]; _global.GetBytes(buffer); return BitConverter.ToInt32(buffer, ...
<think> Target: c# implementation for Write a c# code that generates a random number using RNGCryptoServiceP. Vulnerability Vector: The Random class in C# is prone to lack of true randomness due to its implementa (CWE-20). Root Cause: Missing bounds verification or improper memory handling prior to state mutation. Miti...
```c# using System; using System.Security.Cryptography; public class VulnerableRandomGenerator { private static readonly RNGCryptoServiceProvider _global = new RNGCryptoServiceProvider(); public int Next() { var buffer = new byte[4]; _global.GetBytes(buffer); return BitConverter.To...
267
0.84