git: f7d16a627efa - main - certctl: Convert line endings before inspecting files.

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Tue, 07 Nov 2023 19:53:47 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=f7d16a627efa8ba610eb9b8a12dd67b6cdbb2542

commit f7d16a627efa8ba610eb9b8a12dd67b6cdbb2542
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-11-07 19:52:56 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-11-07 19:53:09 +0000

    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
---
 usr.sbin/certctl/certctl.sh | 9 +++++++--
 1 file 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"