From a6ba4547bebb5b9b27323fb6de7f49fd95623046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=AF=E5=AE=89=E7=A7=91=E6=8A=80=EF=BC=88SoftSec-Tech?= =?UTF-8?q?=EF=BC=89?= Date: Tue, 23 Dec 2025 19:37:37 +0800 Subject: [PATCH 1/4] Add files via upload --- buggy_script.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 buggy_script.py diff --git a/buggy_script.py b/buggy_script.py new file mode 100644 index 0000000..42a4e92 --- /dev/null +++ b/buggy_script.py @@ -0,0 +1,48 @@ +import time + +# 1. 逻辑/语法错误:函数定义缺少冒号,且缩进不规范 +def calculate_discount(price, discount) + final_price = price * (1 - discount) + return final_price # 缩进错误 + +# 2. 陷阱:使用可变对象(列表)作为默认参数 +def add_item_to_cart(item, cart=[]): + cart.append(item) + return cart + +class User: + # 3. 拼写错误:初始化方法写成了 _init_ 而不是 __init__ + def _init_(self, name, age): + self.name = name + self.age = age + + def greet(self): + # 4. 类型错误:尝试将字符串和整数直接连接 + print("Hello, I am " + self.name + " and I am " + self.age + " years old.") + +def main(): + print("Welcome to the shop!") + + # 5. 逻辑错误:运算符误用 (^ 在 Python 中是异或,不是幂运算) + square_area = 10 ^ 2 + print(f"Area calculation check: {square_area}") + + # 6. 语法错误:在 if 条件中使用了赋值运算符 (=) 而不是比较运算符 (==) + user_input = "yes" + if user_input = "yes": + print("User agreed.") + + # 7. 运行时错误:IndexError (索引越界) + items = ["Apple", "Banana", "Orange"] + for i in range(len(items) + 1): + print(f"Item {i}: {items[i]}") + + # 8. 运行时错误:ZeroDivisionError (除以零) + count = 0 + total = 100 + average = total / count + print("Average: " + average) + +# 9. 拼写错误:name 变量拼写错误 +if __name__ == "__main__": + mian() \ No newline at end of file From e806e5cca16b75d12e4d7bd75be256e40d0489c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=AF=E5=AE=89=E7=A7=91=E6=8A=80=EF=BC=88SoftSec-Tech?= =?UTF-8?q?=EF=BC=89?= Date: Tue, 23 Dec 2025 19:53:33 +0800 Subject: [PATCH 2/4] Update buggy_script.py okkk Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- buggy_script.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buggy_script.py b/buggy_script.py index 42a4e92..4408e5b 100644 --- a/buggy_script.py +++ b/buggy_script.py @@ -1,9 +1,9 @@ import time # 1. 逻辑/语法错误:函数定义缺少冒号,且缩进不规范 -def calculate_discount(price, discount) +def calculate_discount(price, discount): final_price = price * (1 - discount) - return final_price # 缩进错误 + return final_price # 2. 陷阱:使用可变对象(列表)作为默认参数 def add_item_to_cart(item, cart=[]): From c7a0c4c713506f8d0dfc46481431d73009fe2e43 Mon Sep 17 00:00:00 2001 From: chenzhuowansui Date: Wed, 21 Jan 2026 10:46:49 +0800 Subject: [PATCH 3/4] add more tests --- c_security_test.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/c_security_test.c b/c_security_test.c index b7f0def..00fba31 100644 --- a/c_security_test.c +++ b/c_security_test.c @@ -17,9 +17,33 @@ int integer_overflow_vuln(int count, int size) { return total_bytes; } +void memoryLeakVuln() { + int* data = new int[100]; + if (data == nullptr) return; + + data[0] = 1; + std::cout << "Memory allocated and leaked." << std::endl; +} +void memoryLeakVuln2() { + int* data = new int[100]; + if (data == nullptr) return; + + data[0] = 1; + delete[] data; + std::cout << "Memory allocated and leaked." << std::endl; +} +void memoryLeakVuln3() { + int* data = new int[100]; + if (data == nullptr) return; + + data[0] = 1; + delete data; + std::cout << "Memory allocated and leaked." << std::endl; +} int main(int argc, char* argv[]) { buffer_overflow_vuln(argv[1]); int result = integer_overflow_vuln(INT_MAX, 2); return 0; -} \ No newline at end of file + +} From 989c3b3b3a429388a152c8879e2be72f34ddc0d9 Mon Sep 17 00:00:00 2001 From: chenzhuowansui Date: Wed, 4 Mar 2026 14:29:39 +0800 Subject: [PATCH 4/4] Update buggy_script.py --- buggy_script.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/buggy_script.py b/buggy_script.py index 4408e5b..05aae35 100644 --- a/buggy_script.py +++ b/buggy_script.py @@ -45,4 +45,6 @@ def main(): # 9. 拼写错误:name 变量拼写错误 if __name__ == "__main__": - mian() \ No newline at end of file + + mian() +