Skip to content

Commit ebcf76f

Browse files
committed
fix concurrency issue when using OAuth2Verify metadata
- closes #37; thanks @rtitle - fix memory leak in cURL writeback function - release 1.4.5.1 Signed-off-by: Hans Zandbelt <hans.zandbelt@zmartzone.eu>
1 parent 9091525 commit ebcf76f

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
08/22/2022
2+
- fix concurrency issue when using OAuth2Verify metadata; see #37; thanks @rtitle
3+
- fix memory leak in cURL writeback function
4+
- release 1.4.5.1
5+
16
07/28/2022
27
- fix memory leak when using OAuth2Verify metadata
38

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([liboauth2],[1.4.5],[hans.zandbelt@zmartzone.eu])
1+
AC_INIT([liboauth2],[1.4.5.1],[hans.zandbelt@zmartzone.eu])
22

33
AM_INIT_AUTOMAKE([foreign no-define subdir-objects])
44
AC_CONFIG_MACRO_DIR([m4])

src/http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ static size_t oauth2_http_curl_buf_write(void *contents, size_t size,
923923
memcpy(newptr, mem->memory, mem->size);
924924
memcpy(&(newptr[mem->size]), contents, realsize);
925925
mem->size += realsize;
926+
oauth2_mem_free(mem->memory);
926927
mem->memory = newptr;
927928
mem->memory[mem->size] = 0;
928929

src/oauth2.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,9 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
502502
char *response = NULL;
503503
json_t *json_metadata = NULL, *json_jwks_uri = NULL,
504504
*json_introspection_endpoint;
505-
const char *jwks_uri = NULL, *introspection_endpoint = NULL;
505+
oauth2_jose_jwt_verify_ctx_t *jwks_uri_verify = NULL;
506+
oauth2_introspect_ctx_t *introspect_ctx = NULL;
507+
const char *jwks_uri = NULL, *introspection_uri = NULL;
506508
char *peek = NULL;
507509

508510
if ((verify == NULL) || (verify->ctx == NULL) ||
@@ -538,12 +540,14 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
538540
oauth2_warn(log, "\"jwks_uri\" value is not a string");
539541
}
540542
}
541-
542543
if (jwks_uri) {
544+
// NB: need a copy because we're going to modify a static/shared config setting
545+
jwks_uri_verify =
546+
oauth2_jose_jwt_verify_ctx_clone(log, ptr->jwks_uri_verify);
543547
oauth2_cfg_endpoint_set_url(
544-
ptr->jwks_uri_verify->jwks_provider->jwks_uri->endpoint,
548+
jwks_uri_verify->jwks_provider->jwks_uri->endpoint,
545549
jwks_uri);
546-
rc = oauth2_jose_jwt_verify(log, ptr->jwks_uri_verify, token,
550+
rc = oauth2_jose_jwt_verify(log, jwks_uri_verify, token,
547551
json_payload, s_payload);
548552
if (rc == true)
549553
goto end;
@@ -555,7 +559,7 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
555559
json_object_get(json_metadata, "introspection_endpoint");
556560
if (json_introspection_endpoint) {
557561
if (json_is_string(json_introspection_endpoint)) {
558-
introspection_endpoint =
562+
introspection_uri =
559563
json_string_value(json_introspection_endpoint);
560564
} else {
561565
oauth2_warn(
@@ -564,10 +568,13 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
564568
}
565569
}
566570

567-
if (introspection_endpoint) {
568-
oauth2_cfg_endpoint_set_url(ptr->introspect->endpoint,
569-
introspection_endpoint);
570-
rc = _oauth2_introspect_verify(log, ptr->introspect, token,
571+
if (introspection_uri) {
572+
// NB: need a copy because we're going to modify a static/shared config setting
573+
introspect_ctx =
574+
oauth2_introspect_ctx_clone(log, ptr->introspect);
575+
oauth2_cfg_endpoint_set_url(introspect_ctx->endpoint,
576+
introspection_uri);
577+
rc = _oauth2_introspect_verify(log, introspect_ctx, token,
571578
json_payload, s_payload);
572579
if (rc == true)
573580
goto end;
@@ -581,6 +588,10 @@ static bool _oauth2_metadata_verify_callback(oauth2_log_t *log,
581588
json_decref(json_metadata);
582589
if (response)
583590
oauth2_mem_free(response);
591+
if (jwks_uri_verify)
592+
oauth2_jose_jwt_verify_ctx_free(log, jwks_uri_verify);
593+
if (introspect_ctx)
594+
oauth2_introspect_ctx_free(log, introspect_ctx);
584595

585596
return rc;
586597
}

0 commit comments

Comments
 (0)