From 3530a84c289fd4920f82019056bbf1f4677e8d70 Mon Sep 17 00:00:00 2001 From: Hans Zandbelt Date: Sun, 15 Dec 2024 13:30:06 +0100 Subject: [PATCH] address Coverity warnings in test/test.c and test/test-cmd.c Signed-off-by: Hans Zandbelt --- test/test-cmd.c | 11 +++++++---- test/test.c | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/test-cmd.c b/test/test-cmd.c index a0ffaf65..982ce61f 100644 --- a/test/test-cmd.c +++ b/test/test-cmd.c @@ -78,7 +78,7 @@ int file_read(apr_pool_t *pool, const char *path, char **rbuf) { *rbuf = apr_pcalloc(pool, len + 1); rc = apr_file_read_full(fd, *rbuf, len, &bytes_read); - if (rc != APR_SUCCESS) { + if ((rc != APR_SUCCESS) || (bytes_read < 1)) { fprintf(stderr, "could not read file %s: %s", path, apr_strerror(rc, s_err, sizeof(s_err))); return -1; } @@ -86,7 +86,7 @@ int file_read(apr_pool_t *pool, const char *path, char **rbuf) { (*rbuf)[bytes_read] = '\0'; bytes_read--; - while ((*rbuf)[bytes_read] == '\n') { + while ((bytes_read > 0) && ((*rbuf)[bytes_read] == '\n')) { (*rbuf)[bytes_read] = '\0'; bytes_read--; } @@ -134,7 +134,7 @@ int sign(int argc, char **argv, apr_pool_t *pool) { return -1; } - fprintf(stdout, "%s", cser); + fprintf(stdout, "%s\n", cser); cjose_jws_release(jws); cjose_jwk_release(jwk); @@ -428,8 +428,11 @@ int uuid(int argc, char **argv, apr_pool_t *pool) { unsigned long i = 0; oidc_session_t z; - if (argc > 2) + if (argc > 2) { n = _oidc_str_to_int(argv[2], n); + if ((n < 0) || (n > 25000000 * 10)) + n = 25000000; + } request_rec *r = request_setup(pool); diff --git a/test/test.c b/test/test.c index b5ca8cad..cf6aace0 100644 --- a/test/test.c +++ b/test/test.c @@ -129,7 +129,7 @@ static char *_jwk_parse(apr_pool_t *pool, const char *s, oidc_jwk_t **jwk, oidc_ } static char *test_private_key_parse(apr_pool_t *pool) { - oidc_jose_error_t err; + oidc_jose_error_t err = {{'\0'}, 0, {'\0'}, {'\0'}}; BIO *input = NULL; oidc_jwk_t *jwk = NULL; int isPrivateKey = 1; @@ -191,7 +191,7 @@ static char *test_private_key_parse(apr_pool_t *pool) { static char *test_public_key_parse(apr_pool_t *pool) { - oidc_jose_error_t err; + oidc_jose_error_t err = {{'\0'}, 0, {'\0'}, {'\0'}}; oidc_jwk_t *jwk, *jwkCert = NULL; BIO *input, *inputCert = NULL; @@ -1865,8 +1865,8 @@ static request_rec *test_setup(apr_pool_t *pool) { oidc_dir_cfg_t *d_cfg = oidc_cfg_dir_config_create(request->pool, NULL); - request->server->module_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *) * kEls); - request->per_dir_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *) * kEls); + request->server->module_config = apr_pcalloc(request->pool, sizeof(void *) * kEls); + request->per_dir_config = apr_pcalloc(request->pool, sizeof(void *) * kEls); ap_set_module_config(request->server->module_config, &auth_openidc_module, cfg); ap_set_module_config(request->per_dir_config, &auth_openidc_module, d_cfg);