/* Provenance: openssl/openssl hash_dir (fixed). * repo: openssl/openssl * commit: 2c9c35870601b4a44d86ddbf512b38df38285cfa * parent: abebcec7b1a30fbb1fd5c5cbbe8817690c139163 * commit_url: https://github.com/openssl/openssl/commit/2c9c35870601b4a44d86ddbf512b38df38285cfa * cve: CVE-2022-2068 * license: Apache-2.0 * function: hash_dir * relpath: tools/c_rehash.in */ sub hash_dir { my $dir = shift; my %hashlist; print "Doing $dir\n"; if (!chdir $dir) { print STDERR "WARNING: Cannot chdir to '$dir', $!\n"; return; } opendir(DIR, ".") || print STDERR "WARNING: Cannot opendir '.', $!\n"; my @flist = sort readdir(DIR); closedir DIR; if ( $removelinks ) { # Delete any existing symbolic links foreach (grep {/^[\da-f]+\.r{0,1}\d+$/} @flist) { if (-l $_) { print "unlink $_\n" if $verbose; unlink $_ || warn "Can't unlink $_, $!\n"; } } } FILE: foreach $fname (grep {/\.(pem)|(crt)|(cer)|(crl)$/} @flist) { # Check to see if certificates and/or CRLs present. my ($cert, $crl) = check_file($fname); if (!$cert && !$crl) { print STDERR "WARNING: $fname does not contain a certificate or CRL: skipping\n"; next; } link_hash_cert($fname) if ($cert); link_hash_crl($fname) if ($crl); } chdir $pwd; }