[v3,0/7] Fix some libm static issues
[platform/upstream/glibc.git] / scripts / process-advisories.sh
1 #!/bin/bash -e
2 # Copyright The GNU Toolchain Authors.
3 # This file is part of the GNU C Library.
4 #
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <https://www.gnu.org/licenses/>.
18
19 if ! [ -d advisories ]; then
20   echo "error: Run me from the toplevel directory of the glibc repository."
21   exit 1
22 fi
23
24 command=$1
25
26 usage () {
27     cat >&2 <<EOF
28 usage: $0 {update|news}
29 EOF
30     exit 1
31 }
32
33 command="$1"
34
35 case "$command" in
36     update|news)
37     ;;
38     *)
39         usage
40         ;;
41 esac
42
43 get_rel() {
44   rel=$(git describe $1 | sed 's/glibc-\([^g]\+\)-g.*/\1/')
45   # If the latest tag for the commit is the development tag, then increment
46   # the release version.
47   if echo $rel | grep -q "\.9000"; then
48     rel=$(echo $rel | sed 's/2\.\([0-9]\+\)\.9000.*/\1/')
49     rel="2.$((rel+1))"
50   fi
51   echo $rel
52 }
53
54 advisories_update() {
55   advisory=$1
56
57   if [ -z $1 ]; then
58     echo "Usage: $0 update GLIBC-SA-YYYY-NNNN"
59     exit 1
60   fi
61
62   advisory_file=advisories/$advisory
63
64   grep --color=none Commit $advisory_file | awk '{printf "%s %s\n", $1, $2}' |
65     while read t r; do
66       rel=$(get_rel $r)
67       echo "*** Updating: $t $r ($rel)"
68       sed -i "s/^$t $r.*/$t $r ($rel)/" $advisory_file
69     done
70 }
71
72 advisories_news() {
73   rel=$(get_rel "HEAD")
74   for f in $(grep -l "^Fix-Commit: .* ($rel)$" advisories/*); do
75     echo -e "  $(basename $f):"
76     cve_id=$(sed -n 's/CVE-Id: \(.*\)/\1/p' $f)
77     echo "$(head -1 $f) ($cve_id)" | fold -w 68 -s |
78       while read line; do
79         echo "    $line"
80       done
81     echo
82   done
83 }
84
85 advisories_$command $2