diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2023-11-07 19:52:56 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2023-11-07 19:53:09 +0000 |
commit | f7d16a627efa8ba610eb9b8a12dd67b6cdbb2542 (patch) | |
tree | 5093758c914ff37b978f92d690a80b1b0652de4b | |
parent | 4e0e01bf6511c28212d7dff94fe131a502e13026 (diff) | |
download | src-f7d16a627efa8ba610eb9b8a12dd67b6cdbb2542.tar.gz src-f7d16a627efa8ba610eb9b8a12dd67b6cdbb2542.zip |
certctl: Convert line endings before inspecting files.
This ensures that certificate files or bundles with DOS or Mac line
endings are recognized as such and handled identically to those with
Unix line endings.
PR: 274952
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D42490
-rwxr-xr-x | usr.sbin/certctl/certctl.sh | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.sbin/certctl/certctl.sh b/usr.sbin/certctl/certctl.sh index 2ffa94bc7db7..997a7d835d53 100755 --- a/usr.sbin/certctl/certctl.sh +++ b/usr.sbin/certctl/certctl.sh @@ -71,6 +71,11 @@ cert_files_in() \) 2>/dev/null } +eolcvt() +{ + cat "$@" | tr -s '\r' '\n' +} + do_hash() { local hash @@ -181,7 +186,7 @@ do_scan() IFS="$oldIFS" for CFILE in $(cert_files_in "$@") ; do verbose "Reading $CFILE" - case $(egrep -c '^-+BEGIN CERTIFICATE-+$' "$CFILE") in + case $(eolcvt "$CFILE" | egrep -c '^-+BEGIN CERTIFICATE-+$') in 0) ;; 1) @@ -190,7 +195,7 @@ do_scan() *) verbose "Multiple certificates found, splitting..." SPLITDIR=$(mktemp -d) - egrep '^(---|[0-9A-Za-z/+=]+$)' "$CFILE" | \ + eolcvt "$CFILE" | egrep '^(---|[0-9A-Za-z/+=]+$)' | \ split -p '^-+BEGIN CERTIFICATE-+$' - "$SPLITDIR/x" for CERT in $(find "$SPLITDIR" -type f) ; do "$CFUNC" "$CERT" |