X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=apps%2Frehash.c;h=38084a247fb854601144a38569a33193afb923a2;hp=b235e1bf25da4462f0fa7d7920e5a37fee5b0397;hb=d6482a82bc2228327aa4ba98aeeecd9979542a31;hpb=5278dec375c9a2d991db4c533b60e09c6c80e6e3 diff --git a/apps/rehash.c b/apps/rehash.c index b235e1bf25..38084a247f 100644 --- a/apps/rehash.c +++ b/apps/rehash.c @@ -59,7 +59,7 @@ #include "apps.h" -#if defined(unix) || defined(__APPLE__) +#if defined(OPENSSL_SYS_UNIX) || defined(__APPLE__) # include # include # include @@ -74,6 +74,9 @@ # include +# ifndef NAME_MAX +# define NAME_MAX 255 +# endif # define MAX_COLLISIONS 256 typedef struct hentry_st { @@ -172,7 +175,7 @@ static int add_entry(enum Type type, unsigned int hash, const char *filename, ep = app_malloc(sizeof(*ep), "collision bucket"); *ep = nilhentry; ep->old_id = ~0; - ep->filename = BUF_strdup(filename); + ep->filename = OPENSSL_strdup(filename); if (bp->last_entry) bp->last_entry->next = ep; if (bp->first_entry == NULL) @@ -199,7 +202,7 @@ static int handle_symlink(const char *filename, const char *fullpath) unsigned int hash = 0; int i, type, id; unsigned char ch; - char linktarget[NAME_MAX], *endptr; + char linktarget[PATH_MAX], *endptr; ssize_t n; for (i = 0; i < 8; i++) { @@ -239,16 +242,17 @@ static int do_file(const char *filename, const char *fullpath, enum Hash h) BIO *b; const char *ext; unsigned char digest[EVP_MAX_MD_SIZE]; - int i, type, errs = 0; + int type, errs = 0; + size_t i; /* Does it end with a recognized extension? */ if ((ext = strrchr(filename, '.')) == NULL) goto end; - for (i = 0; i < (int)OSSL_NELEM(extensions); i++) { + for (i = 0; i < OSSL_NELEM(extensions); i++) { if (strcasecmp(extensions[i], ext + 1) == 0) break; } - if (i >= (int)OSSL_NELEM(extensions)) + if (i >= OSSL_NELEM(extensions)) goto end; /* Does it have X.509 data in it? */ @@ -280,6 +284,9 @@ static int do_file(const char *filename, const char *fullpath, enum Hash h) type = TYPE_CRL; name = X509_CRL_get_issuer(x->crl); X509_CRL_digest(x->crl, evpmd, digest, NULL); + } else { + ++errs; + goto end; } if (name) { if ((h == HASH_NEW) || (h == HASH_BOTH)) @@ -303,14 +310,19 @@ static int do_dir(const char *dirname, enum Hash h) OPENSSL_DIR_CTX *d = NULL; struct stat st; unsigned char idmask[MAX_COLLISIONS / 8]; - int i, n, nextid, buflen, errs = 0; + int n, nextid, buflen, errs = 0; + size_t i; const char *pathsep; const char *filename; char *buf; + if (app_access(dirname, W_OK) < 0) { + BIO_printf(bio_err, "Skipping %s, can't write\n", dirname); + return 1; + } buflen = strlen(dirname); pathsep = (buflen && dirname[buflen - 1] == '/') ? "" : "/"; - buflen += NAME_MAX + 2; + buflen += NAME_MAX + 1 + 1; buf = app_malloc(buflen, "filename buffer"); if (verbose) @@ -328,7 +340,7 @@ static int do_dir(const char *dirname, enum Hash h) } OPENSSL_DIR_end(&d); - for (i = 0; i < (int)OSSL_NELEM(hash_table); i++) { + for (i = 0; i < OSSL_NELEM(hash_table); i++) { for (bp = hash_table[i]; bp; bp = nextbp) { nextbp = bp->next; nextid = 0; @@ -456,7 +468,7 @@ int rehash_main(int argc, char **argv) while (*argv) errs += do_dir(*argv++, h); } else if ((env = getenv("SSL_CERT_DIR")) != NULL) { - m = BUF_strdup(env); + m = OPENSSL_strdup(env); for (e = strtok(m, ":"); e != NULL; e = strtok(NULL, ":")) errs += do_dir(e, h); OPENSSL_free(m); @@ -479,4 +491,4 @@ int rehash_main(int argc, char **argv) return (1); } -#endif /* defined(unix) || defined(__APPLE__) */ +#endif /* defined(OPENSSL_SYS_UNIX) || defined(__APPLE__) */