Skip to content

Commit 3530a84

Browse files
committed
address Coverity warnings in test/test.c and test/test-cmd.c
Signed-off-by: Hans Zandbelt <[email protected]>
1 parent 792589d commit 3530a84

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

test/test-cmd.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ int file_read(apr_pool_t *pool, const char *path, char **rbuf) {
7878
*rbuf = apr_pcalloc(pool, len + 1);
7979

8080
rc = apr_file_read_full(fd, *rbuf, len, &bytes_read);
81-
if (rc != APR_SUCCESS) {
81+
if ((rc != APR_SUCCESS) || (bytes_read < 1)) {
8282
fprintf(stderr, "could not read file %s: %s", path, apr_strerror(rc, s_err, sizeof(s_err)));
8383
return -1;
8484
}
8585

8686
(*rbuf)[bytes_read] = '\0';
8787

8888
bytes_read--;
89-
while ((*rbuf)[bytes_read] == '\n') {
89+
while ((bytes_read > 0) && ((*rbuf)[bytes_read] == '\n')) {
9090
(*rbuf)[bytes_read] = '\0';
9191
bytes_read--;
9292
}
@@ -134,7 +134,7 @@ int sign(int argc, char **argv, apr_pool_t *pool) {
134134
return -1;
135135
}
136136

137-
fprintf(stdout, "%s", cser);
137+
fprintf(stdout, "%s\n", cser);
138138

139139
cjose_jws_release(jws);
140140
cjose_jwk_release(jwk);
@@ -428,8 +428,11 @@ int uuid(int argc, char **argv, apr_pool_t *pool) {
428428
unsigned long i = 0;
429429
oidc_session_t z;
430430

431-
if (argc > 2)
431+
if (argc > 2) {
432432
n = _oidc_str_to_int(argv[2], n);
433+
if ((n < 0) || (n > 25000000 * 10))
434+
n = 25000000;
435+
}
433436

434437
request_rec *r = request_setup(pool);
435438

test/test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static char *_jwk_parse(apr_pool_t *pool, const char *s, oidc_jwk_t **jwk, oidc_
129129
}
130130

131131
static char *test_private_key_parse(apr_pool_t *pool) {
132-
oidc_jose_error_t err;
132+
oidc_jose_error_t err = {{'\0'}, 0, {'\0'}, {'\0'}};
133133
BIO *input = NULL;
134134
oidc_jwk_t *jwk = NULL;
135135
int isPrivateKey = 1;
@@ -191,7 +191,7 @@ static char *test_private_key_parse(apr_pool_t *pool) {
191191

192192
static char *test_public_key_parse(apr_pool_t *pool) {
193193

194-
oidc_jose_error_t err;
194+
oidc_jose_error_t err = {{'\0'}, 0, {'\0'}, {'\0'}};
195195
oidc_jwk_t *jwk, *jwkCert = NULL;
196196

197197
BIO *input, *inputCert = NULL;
@@ -1865,8 +1865,8 @@ static request_rec *test_setup(apr_pool_t *pool) {
18651865

18661866
oidc_dir_cfg_t *d_cfg = oidc_cfg_dir_config_create(request->pool, NULL);
18671867

1868-
request->server->module_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *) * kEls);
1869-
request->per_dir_config = apr_pcalloc(request->pool, sizeof(ap_conf_vector_t *) * kEls);
1868+
request->server->module_config = apr_pcalloc(request->pool, sizeof(void *) * kEls);
1869+
request->per_dir_config = apr_pcalloc(request->pool, sizeof(void *) * kEls);
18701870
ap_set_module_config(request->server->module_config, &auth_openidc_module, cfg);
18711871
ap_set_module_config(request->per_dir_config, &auth_openidc_module, d_cfg);
18721872

0 commit comments

Comments
 (0)