From 7de72d437e3ab89cbe2b0d05ac869c8577b60015 Mon Sep 17 00:00:00 2001 From: Hans Zandbelt Date: Mon, 6 Nov 2023 10:04:54 +0100 Subject: [PATCH] use _oidc_str_to_int consistently instead of strtol Signed-off-by: Hans Zandbelt --- src/mod_auth_openidc.c | 19 +++++++------------ src/parse.c | 8 +++----- src/util.c | 5 ++--- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/mod_auth_openidc.c b/src/mod_auth_openidc.c index eda139d3..3050b786 100644 --- a/src/mod_auth_openidc.c +++ b/src/mod_auth_openidc.c @@ -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; } /* diff --git a/src/parse.c b/src/parse.c index ad04266e..fda2cacb 100644 --- a/src/parse.c +++ b/src/parse.c @@ -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; } diff --git a/src/util.c b/src/util.c index 7fe6be28..ddfc3d3d 100644 --- a/src/util.c +++ b/src/util.c @@ -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;