Fix for wc_ReadDirFirst to return non-zero value if no files found. Fix for wolfSSL_CTX_load_verify_locations to not return failure due to wc_ReadDirNext “no more files” -1 response.

This commit is contained in:
David Garske 2017-06-21 10:35:47 -07:00
parent 2f9f746053
commit d75a9f2436
2 changed files with 13 additions and 5 deletions

View File

@ -5621,6 +5621,7 @@ int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
const char* path) const char* path)
{ {
int ret = SSL_SUCCESS; int ret = SSL_SUCCESS;
int fileRet;
WOLFSSL_ENTER("wolfSSL_CTX_load_verify_locations"); WOLFSSL_ENTER("wolfSSL_CTX_load_verify_locations");
@ -5644,16 +5645,21 @@ int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
#endif #endif
/* try to load each regular file in path */ /* try to load each regular file in path */
ret = wc_ReadDirFirst(readCtx, path, &name); fileRet = wc_ReadDirFirst(readCtx, path, &name);
while (ret == 0 && name) { while (fileRet == 0 && name) {
ret = ProcessFile(ctx, name, SSL_FILETYPE_PEM, CA_TYPE, ret = ProcessFile(ctx, name, SSL_FILETYPE_PEM, CA_TYPE,
NULL, 0, NULL); NULL, 0, NULL);
if (ret != SSL_SUCCESS) if (ret != SSL_SUCCESS)
break; break;
ret = wc_ReadDirNext(readCtx, path, &name); fileRet = wc_ReadDirNext(readCtx, path, &name);
} }
wc_ReadDirClose(readCtx); wc_ReadDirClose(readCtx);
/* pass directory read failure to response code */
if (ret == SSL_SUCCESS && fileRet != -1) {
ret = fileRet;
}
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
XFREE(readCtx, ctx->heap, DYNAMIC_TYPE_DIRCTX); XFREE(readCtx, ctx->heap, DYNAMIC_TYPE_DIRCTX);
#endif #endif

View File

@ -197,9 +197,10 @@ int wolfCrypt_Cleanup(void)
#if !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) #if !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
/* File Handling Helpers */ /* File Handling Helpers */
/* returns 0 if file found, -1 if no files or negative error */
int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name)
{ {
int ret = 0; int ret = -1; /* default to no files found */
if (name) if (name)
*name = NULL; *name = NULL;
@ -258,9 +259,10 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name)
return ret; return ret;
} }
/* returns 0 if file found, -1 if no more files */
int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name)
{ {
int ret = -1; int ret = -1; /* default to no file found */
if (name) if (name)
*name = NULL; *name = NULL;