Skip to content

support cert c optional rule help generation #880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions scripts/help/cert-help-extraction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
from argparse import ArgumentParser
from typing import Generator
import tempfile
import re
import urllib.request
Expand All @@ -23,6 +24,7 @@

CERT_WIKI = "https://wiki.sei.cmu.edu"
RULES_LIST_C = "/confluence/display/c/2+Rules"
RECOMMENDED_LIST_C = "/confluence/display/c/3+Recommendations"
RULES_LIST_CPP = "/confluence/display/cplusplus/2+Rules"

cache_path = script_path.parent / '.cache'
Expand All @@ -47,16 +49,22 @@ def soupify(url: str) -> BeautifulSoup:

return BeautifulSoup(content, 'html.parser')


def get_rules():
rules = []
for soup in [soupify(f"{CERT_WIKI}{RULES_LIST_C}"), soupify(f"{CERT_WIKI}{RULES_LIST_CPP}")]:
def get_rule_listings() -> Generator[Tag, None, None]:
for rule_list_id in [RULES_LIST_C, RULES_LIST_CPP]:
soup = soupify(f"{CERT_WIKI}{rule_list_id}")
if soup == None:
return None

rule_listing_start = soup.find(
continue
yield soup.find(
"h1", string="Rule Listing")

soup = soupify(f"{CERT_WIKI}{RECOMMENDED_LIST_C}")
if soup != None:
yield soup.find("h1", string="Recommendation Listing")

def get_rules():
rules = []
for rule_listing_start in get_rule_listings():
for link in rule_listing_start.next_element.next_element.find_all('a'):
if '-C' in link.string:
rule, title = map(str.strip, link.string.split('.', 1))
Expand Down Expand Up @@ -214,6 +222,8 @@ def helper(node):
# Fix a broken url present in many CERT-C pages
if node.name == 'a' and 'href' in node.attrs and node['href'] == "http://BB. Definitions#vulnerability":
node['href'] = "https://wiki.sei.cmu.edu/confluence/display/c/BB.+Definitions#BB.Definitions-vulnerability"
elif node.name == 'a' and 'href' in node.attrs and node['href'] == "http://BB. Definitions#unexpected behavior":
node['href'] = "https://wiki.sei.cmu.edu/confluence/display/c/BB.+Definitions#BB.Definitions-unexpectedbehavior"
# Turn relative URLs into absolute URLS
elif node.name == 'a' and 'href' in node.attrs and node['href'].startswith("/confluence"):
node['href'] = f"{CERT_WIKI}{node['href']}"
Expand Down
Loading