ssl-cert-check icon indicating copy to clipboard operation
ssl-cert-check copied to clipboard

-f does not work with process substitution

Open codigoergosum opened this issue 2 years ago • 1 comments

$ bash -x ssl-cert-check -f <(echo -e 'example.com 443')

fails because /dev/fd/63 does not satisfy the test:

elif [ -f "${SERVERFILE}" ]; then

which looks for an extant regular file. However, a regular file should not be required, just a readable one. In bash, I'd suggest the -r test instead--I can't speak to other shells.

codigoergosum avatar Oct 20 '22 23:10 codigoergosum

Similarly the following does not work due to [ -f "${SERVERFILE}" ]:

$ echo example.com 443 | ssl-cert-check -f /dev/stdin

Another disadvantage is the race condition between the test and grep actually opening the file. Not a big issue, but not ideal either. I propose to change the code like this:

elif [ -n "${SERVERFILE}" ]; then
    print_heading

    grep -E -v '(^#|^$)' "${SERVERFILE}" | while read HOST PORT
    do
        if [ "$PORT" = "FILE" ]; then
            check_file_status "${HOST}" "FILE" "${HOST}"
        else
            check_server_status "${HOST}" "${PORT}"
        fi
    done
    if [ ${PIPESTATUS[0]} != 0 ]
    then
	echo "Error opening ${SERVERFILE}"
    else
        print_summary
    fi

Happy to raise a pull request if desired.

pillilz avatar Apr 02 '23 20:04 pillilz