Skip to content

Commit

Permalink
code: apply boundary checks on oidc_metrics_shm_size in metrics.c
Browse files Browse the repository at this point in the history
and use a global static for performance reasons; enable SonarQube

Signed-off-by: Hans Zandbelt <[email protected]>
  • Loading branch information
zandbelt committed Dec 16, 2024
1 parent c06ebff commit beb9f0b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- code: declare introspection_endpoint_method member as int so it can be set to OIDC_CONFIG_POS_INT_UNSET without warning
- code: check return value of oidc_get_provider_from_session and oidc_refresh_token_grant in logout.c
- code: avoid potential crash on non-conformant literal IPv6 adresses in oidc_util_current_url_host
- code: apply boundary checks on oidc_metrics_shm_size and use a global static for performance reasons

12/15/2024
- add Coverity Github action
Expand Down
17 changes: 14 additions & 3 deletions src/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,22 @@ static inline int oidc_metrics_get_env_int(const char *name, int dval) {

#define OIDC_METRICS_CACHE_JSON_MAX_ENV_VAR "OIDC_METRICS_CACHE_JSON_MAX"

static apr_size_t _oidc_metrics_shm_size = 0;

/*
* get the size of the to-be-allocated shared memory segment
*/
static inline int oidc_metrics_shm_size(server_rec *s) {
return oidc_metrics_get_env_int(OIDC_METRICS_CACHE_JSON_MAX_ENV_VAR, OIDC_METRICS_CACHE_JSON_MAX_DEFAULT);
static inline apr_size_t oidc_metrics_shm_size(server_rec *s) {
if (_oidc_metrics_shm_size == 0) {
int n =
oidc_metrics_get_env_int(OIDC_METRICS_CACHE_JSON_MAX_ENV_VAR, OIDC_METRICS_CACHE_JSON_MAX_DEFAULT);
if ((n < 1) || (n > 1024 * 256 * 4 * 100)) {
oidc_serror(s, "environment value %s out of bounds, fallback to default",
OIDC_METRICS_CACHE_JSON_MAX_ENV_VAR);
_oidc_metrics_shm_size = OIDC_METRICS_CACHE_JSON_MAX_DEFAULT;
}
}
return _oidc_metrics_shm_size;
}

/*
Expand All @@ -354,7 +365,7 @@ static inline void oidc_metrics_storage_set(server_rec *s, const char *value) {
if (n > oidc_metrics_shm_size(s))
oidc_serror(s,
"json value too large: set or increase system environment variable %s to a value "
"larger than %d",
"larger than %" APR_SIZE_T_FMT,
OIDC_METRICS_CACHE_JSON_MAX_ENV_VAR, oidc_metrics_shm_size(s));
else
_oidc_memcpy(p, value, n);
Expand Down

0 comments on commit beb9f0b

Please sign in to comment.