Skip to content

Commit a2cfc06

Browse files
committed
avoid segfault and improve error reporting when apr_temp_dir_get fails
when a temp directory cannot be found on the system upon initalizing cache mutexes and file cache; see #1288; thanks @ErmakovDmitriy Signed-off-by: Hans Zandbelt <[email protected]>
1 parent c8c86aa commit a2cfc06

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ reporting bugs, providing fixes, suggesting useful features or other:
9393
adg-mh <https://github.com/adg-mh>
9494
David P. Discher <https://github.com/daviddpd>
9595
ryanwilliamnicholls <https://github.com/ryanwilliamnicholls>
96+
Dmitrii Ermakov <https://github.com/ErmakovDmitriy>

ChangeLog

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
- metadata: fix caching of JWKs from jwks_uri when using the default expiry setting (i.e. not using OIDCJWKSRefreshInterval)
33
and avoid fetching JWKs from the jwks_uri for each user login; also addresses Redis cache
44
error entries the log [ERR invalid expire time in 'setex' command]
5+
- avoid segfault and improve error reporting in case apr_temp_dir_get fails when a temp directory cannot be found
6+
on the system upon initalizing cache mutexes and file cache; see #1288; thanks @ErmakovDmitriy
57

68
11/21/2024
79
- add option to set local address for outgoing HTTP requests; see #1283; thanks @studersi

src/cache/cache.h

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ typedef struct oidc_cache_mutex_t {
8484
} oidc_cache_mutex_t;
8585

8686
oidc_cache_mutex_t *oidc_cache_mutex_create(apr_pool_t *pool, apr_byte_t global);
87+
char *oidc_cache_status2str(apr_pool_t *p, apr_status_t statcode);
8788
apr_byte_t oidc_cache_mutex_post_config(server_rec *s, oidc_cache_mutex_t *m, const char *type);
8889
apr_status_t oidc_cache_mutex_child_init(apr_pool_t *p, server_rec *s, oidc_cache_mutex_t *m);
8990
apr_byte_t oidc_cache_mutex_lock(apr_pool_t *pool, server_rec *s, oidc_cache_mutex_t *m);

src/cache/common.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ apr_byte_t oidc_cache_mutex_post_config(server_rec *s, oidc_cache_mutex_t *m, co
8686
const char *dir;
8787

8888
/* construct the mutex filename */
89-
apr_temp_dir_get(&dir, s->process->pool);
89+
rv = apr_temp_dir_get(&dir, s->process->pool);
90+
if (rv != APR_SUCCESS) {
91+
oidc_serror(s, "apr_temp_dir_get failed: could not find a temp dir: %s",
92+
oidc_cache_status2str(s->process->pool, rv));
93+
return FALSE;
94+
}
95+
9096
m->mutex_filename =
9197
apr_psprintf(s->process->pool, "%s/mod_auth_openidc_%s_mutex.%ld.%pp", dir, type, (long int)getpid(), s);
9298

src/cache/file.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ typedef struct {
6464

6565
/* post config routine */
6666
int oidc_cache_file_post_config(server_rec *s) {
67+
apr_status_t rv = APR_SUCCESS;
6768
oidc_cfg_t *cfg = (oidc_cfg_t *)ap_get_module_config(s->module_config, &auth_openidc_module);
6869
if (cfg->cache.file_dir == NULL) {
6970
/* by default we'll use the OS specified /tmp dir for cache files */
70-
apr_temp_dir_get((const char **)&cfg->cache.file_dir, s->process->pool);
71+
rv = apr_temp_dir_get((const char **)&cfg->cache.file_dir, s->process->pool);
72+
if (rv != APR_SUCCESS) {
73+
oidc_serror(s, "apr_temp_dir_get failed: could not find a temp dir: %s",
74+
oidc_cache_status2str(s->process->pool, rv));
75+
return HTTP_INTERNAL_SERVER_ERROR;
76+
}
7177
}
7278
return OK;
7379
}

0 commit comments

Comments
 (0)