Revert "Remove unnecessary stat calls from by_dir.c"
This reverts commit d4faa8d63a06a5feff2e5b68695adf9bf8fd1f81. This turns
out to have been load-bearing, but more investigation and tests are
needed. See bug.
Bug: 708
Change-Id: I70eac81dbab01a7d47092719b85a004373851468
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/66928
Reviewed-by: Bob Beck <bbe@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c
index d49220d..16d2dfb 100644
--- a/crypto/x509/by_dir.c
+++ b/crypto/x509/by_dir.c
@@ -66,6 +66,12 @@
#include "../internal.h"
#include "internal.h"
+#if !defined(OPENSSL_NO_POSIX_IO)
+#include <sys/stat.h>
+#include <sys/types.h>
+#endif
+
+
typedef struct lookup_dir_hashes_st {
uint32_t hash;
int suffix;
@@ -311,6 +317,21 @@
for (;;) {
snprintf(b->data, b->max, "%s/%08" PRIx32 ".%s%d", ent->dir, h, postfix,
k);
+#if !defined(OPENSSL_NO_POSIX_IO)
+#if defined(_WIN32) && !defined(stat)
+#define stat _stat
+#endif
+ {
+ // TODO(crbug.com/boringssl/708): This call should be redundant with
+ // |X509_load_*_file| failing below, but it turns out to be
+ // load-bearing. Clean this up.
+ struct stat st;
+ if (stat(b->data, &st) < 0) {
+ break;
+ }
+ }
+#endif
+ // found one.
if (type == X509_LU_X509) {
if ((X509_load_cert_file(xl, b->data, ent->dir_type)) == 0) {
break;