Skip to content

Commit

Permalink
use _oidc_str_to_int consistently instead of strtol
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 Nov 6, 2023
1 parent 00cc967 commit 7de72d4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
19 changes: 7 additions & 12 deletions src/mod_auth_openidc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,18 +2144,13 @@ static apr_byte_t oidc_save_in_session(request_rec *r, oidc_cfg *c,
* parse the expiry for the access token
*/
static int oidc_parse_expires_in(request_rec *r, const char *expires_in) {
if (expires_in != NULL) {
char *ptr = NULL;
long number = strtol(expires_in, &ptr, 10);
if (number <= 0) {
oidc_warn(r,
"could not convert \"expires_in\" value (%s) to a number",
expires_in);
return -1;
}
return number;
}
return -1;
if (expires_in != NULL)
return -1;
int number = _oidc_str_to_int(expires_in);
if (number <= 0)
oidc_warn(r, "could not convert \"expires_in\" value (%s) to a number",
expires_in);
return number;
}

/*
Expand Down
8 changes: 3 additions & 5 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,10 @@ const char *oidc_valid_cookie_domain(apr_pool_t *pool, const char *arg) {
/*
* parse an integer value from a string
*/
const char *oidc_parse_int(apr_pool_t *pool, const char *arg, int *int_value) {
char *endptr = NULL;
int v = strtol(arg, &endptr, 10);
if ((*arg == '\0') || (*endptr != '\0')) {
const char* oidc_parse_int(apr_pool_t *pool, const char *arg, int *int_value) {
if (*arg == '\0')
return apr_psprintf(pool, "invalid integer value: %s", arg);
}
int v = _oidc_str_to_int(arg);
*int_value = v;
return NULL;
}
Expand Down
5 changes: 2 additions & 3 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,9 +1512,8 @@ static int oidc_util_get_chunked_count(request_rec *r, const char *cookieName) {
char *chunkCountValue = oidc_util_get_cookie(r,
oidc_util_get_chunk_count_name(r, cookieName));
if (chunkCountValue != NULL) {
char *endptr = NULL;
chunkCount = strtol(chunkCountValue, &endptr, 10);
if ((*chunkCountValue == '\0') || (*endptr != '\0'))
chunkCount = _oidc_str_to_int(chunkCountValue);
if (*chunkCountValue == '\0')
chunkCount = 0;
}
return chunkCount;
Expand Down

0 comments on commit 7de72d4

Please sign in to comment.