From f7d16a627efa8ba610eb9b8a12dd67b6cdbb2542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Tue, 7 Nov 2023 20:52:56 +0100 Subject: [PATCH] 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 2ffa94bc7db..997a7d835d5 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"