Skip to content

Commit

Permalink
address Coverity warnings in test/test.c and test/test-cmd.c
Browse files Browse the repository at this point in the history
Signed-off-by: Hans Zandbelt <hans.zandbelt@openidc.com>
  • Loading branch information
zandbelt committed Dec 15, 2024
1 parent 792589d commit 3530a84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions test/test-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ 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;
}

(*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--;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3530a84

Please sign in to comment.