aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/cve_update
blob: 5fdcb4662ba60e3ea6a6277dd44bef8289001955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2024 - Greg Kroah-Hartman <gregkh@linuxfoundation.org>
#
# cve_update - Update all existing CVE entries based on the latest information
#	       pulled from the git tree(s).
#
# Will look through the list of all published cve ids and run 'bippy' on them
# to update the mbox and json files.  It is recommended that after this
# happens, submit the json files to CVE again, if version numbers have changed.
#
# This is good to do after older stable kernels have been released as often
# CVEs are included in older stable kernels AFTER they show up in newer ones,
# and this keeps the database at CVE more up to date and friendly for others to
# rely on.  The mbox files generally shouldn't be resent, as that's just noise
# that no one wants to see.
#
# Usage:
#	cve_update
#
# Requires:
#  bippy


# don't use unset variables
set -o nounset

# set where the tool was run from,
# the name of our script,
# and the git version of it
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPT=${0##*/}

help() {
	echo "${SCRIPT}"
	exit 1
}

cd "${DIR}"/../ || exit 1

for id in cve/published/*/*.sha1 ; do
#for id in $(ls cve/published/*/*.sha1) ; do
	tmp_json=$(mktemp "${TMPDIR}/${SCRIPT}XXXX.json" || exit 1)
	tmp_mbox=$(mktemp "${TMPDIR}/${SCRIPT}XXXX.mbox" || exit 1)
	sha=$(cat "${id}")
	cve=$(echo "${id}" | cut -f 1 -d '.' | cut -f 4 -d '/')
	root=$(echo "${id}" | cut -f 1 -d '.')
	#echo "id=${id} sha=${sha} cve=${cve}"
	echo "Updating ${cve}..."

	# Create the new json and mbox files
	"${DIR}"/bippy --cve="${cve}" --sha="${sha}" --json="${tmp_json}" --mbox="${tmp_mbox}"

	# see if the json and/or mbox files actually changed, EXCEPT for the bippy-VERSIONINFO string
	changed=0
	diff=$(diff -u "${root}.json" "${tmp_json}" | grep -v "${tmp_json}" | grep -v "${root}.json" | grep -v "bippy-" | grep -v "^@@ " | grep "^+")
	#echo "diff json=${diff}"
	if [[ "${diff}" != "" ]] ; then
		mv -f "${tmp_json}" "${root}.json"
		echo "	Updated ${root}.json"
		changed=1
	else
		rm "${tmp_json}"
		#echo "diff for json was empty"
	fi

	diff=$(diff -u "${root}.mbox" "${tmp_mbox}" | grep -v "${tmp_mbox}" | grep -v "${root}.mbox" | grep -v "bippy-" | grep -v "^@@ " | grep "^+")
	#echo "diff mbox=${diff}"
	if [[ "${diff}" != "" ]] ; then
		mv -f "${tmp_mbox}" "${root}.mbox"
		echo "	Updated ${root}.mbox"
		changed=1
	else
		rm "${tmp_mbox}"
		#echo "diff for mbox was empty"
	fi
	if [[ "${changed}" == "0" ]] ; then
		echo "	nothing changed"
	fi
done