~kdsch/android-bulletin

adbe66de82c0d692afb51df61a799e743899e0ce — Karl Schultheisz 3 years ago ae6ace8
extract vuln and component from certain headings

Older bulletins used headings of the form

	<vuln> in <component>

, with the tables not including this information.
This patch extracts the information when the heading
has that form.
1 files changed, 32 insertions(+), 6 deletions(-)

M main.go
M main.go => main.go +32 -6
@@ 94,14 94,36 @@ func getCVEs(bulletin bulletin) (entries []entry) {
		return
	}

	doc.Find("h2").Each(func(_ int, patchLevelHeading *goquery.Selection) {
		if !strings.HasPrefix(patchLevelHeading.Text(), "20") {
	doc.Find("h2").Each(func(_ int, h2 *goquery.Selection) {
		if !strings.HasPrefix(h2.Text(), "20") {
			return
		}
		patchLevel := strings.Fields(patchLevelHeading.Text())[0]
		patchLevelHeading.NextFilteredUntil("h3", "h2").Each(func(_ int, componentHeading *goquery.Selection) {
			component := shave(componentHeading.Text())
			colgroup := componentHeading.NextUntil("h3").Find("colgroup")
		patchLevel := strings.Fields(h2.Text())[0]
		h2.NextFilteredUntil("h3", "h2").Each(func(_ int, h3 *goquery.Selection) {
			h3Text := shave(h3.Text())
			var component string
			var vuln string
			if parts := strings.Split(h3Text, " in "); len(parts) == 2 {
				component = parts[1]
				switch parts[0] {
				case "Vulnerabilities":
					// ignore
				case "Remote code execution vulnerability",
					"Remote Code Execution vulnerability":
					vuln = "RCE"
				case "Information disclosure vulnerability":
					vuln = "ID"
				case "Elevation of privilege vulnerability":
					vuln = "EoP"
				case "Denial of service vulnerability":
					vuln = "DoS"
				default:
					fmt.Fprintf(os.Stderr, "%v: unexpected vuln string %q\n", patchLevel, parts[0])
				}
			} else {
				component = h3Text
			}
			colgroup := h3.NextUntil("h3").Find("colgroup")

			// The table is found.
			rows := colgroup.Next().Find("tr")


@@ 135,6 157,10 @@ func getCVEs(bulletin bulletin) (entries []entry) {
					component:  shave(component),
				}

				if vuln != "" {
					e.Type = vuln
				}

				cells.Each(func(index int, cell *goquery.Selection) {
					text := shave(cell.Text())
					heading := headingCells.Eq(index).Text()