Skip to content

Instantly share code, notes, and snippets.

@anon767
Created December 12, 2023 12:01
Show Gist options
  • Save anon767/730d19d79f2eb26836f256ad9ecb8d1d to your computer and use it in GitHub Desktop.
Save anon767/730d19d79f2eb26836f256ad9ecb8d1d to your computer and use it in GitHub Desktop.
Extract cvefixes samples
import pandas as pd
import sqlite3 as lite
from sqlite3 import Error
from pathlib import Path
from datetime import date
import numpy as np
import requests
import difflib as diff
import re
import csv
import ast
from tqdm import tqdm
# pd.set_option('mode.chained_assignment', None)
def create_connection(db_file):
"""
create a connection to sqlite3 database
"""
conn = None
try:
conn = lite.connect(db_file, timeout=10) # connection via sqlite3
# engine = sa.create_engine('sqlite:///' + db_file) # connection via sqlalchemy
# conn = engine.connect()
except Error as e:
print(e)
return conn
conn = create_connection("data/cvefixes.db")
df_c_methods = pd.read_sql_query("SELECT m.file_change_id, m.name, m.code, m.before_change FROM method_change m, file_change f \
WHERE f.file_change_id=m.file_change_id AND f.programming_language='C'", conn)
for i, entry in tqdm(enumerate(df_c_methods.values)):
file_change_id, name, code, before_change = entry
print(before_change)
if before_change == "True":
fh_vuln = open("data/cvefixes/{}_{}.c".format(name, "1"),"a+")
fh_vuln.write(code)
fh_vuln.close()
elif before_change == "False":
fh_cl = open("data/cvefixes/{}_{}.c".format(name, "0"),"a+")
fh_cl.write(code)
fh_cl.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment