Skip to content

Fix potential NULL dereference in ngx_http_auth_spnego_store_delegated_creds() #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions ngx_http_auth_spnego_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ ngx_http_auth_spnego_store_delegated_creds(ngx_http_request_t *r,
ngx_strlen("/") + ngx_strlen(escaped)) +
1;
ccname = (char *)ngx_pcalloc(r->pool, ccname_size);
if (NULL == ccname) {
return NGX_ERROR;
}

ngx_snprintf((u_char *)ccname, ccname_size, "FILE:%s/%*s", P_tmpdir,
ngx_strlen(escaped), escaped);
Expand Down Expand Up @@ -850,6 +853,10 @@ ngx_http_auth_spnego_store_delegated_creds(ngx_http_request_t *r,
ngx_http_auth_spnego_set_variable(r, &var_name, &var_value);

ngx_pool_cleanup_t *cln = ngx_pool_cleanup_add(r->pool, 0);
if (NULL == cln) {
return NGX_ERROR;
}

cln->handler = ngx_http_auth_spnego_krb5_destroy_ccache;
cln->data = ccname;
done:
Expand Down Expand Up @@ -883,7 +890,6 @@ ngx_int_t ngx_http_auth_spnego_basic(ngx_http_request_t *r,
krb5_principal server = NULL;
krb5_creds creds;
krb5_get_init_creds_opt *gic_options = NULL;
int kret = 0;
char *name = NULL;
char *p = NULL;

Expand Down Expand Up @@ -915,9 +921,9 @@ ngx_int_t ngx_http_auth_spnego_basic(ngx_http_request_t *r,
&host_name, &alcf->realm);
}

kret = krb5_parse_name(kcontext, (const char *)service.data, &server);
code = krb5_parse_name(kcontext, (const char *)service.data, &server);

if (kret) {
if (code) {
spnego_log_error("Kerberos error: Unable to parse service name");
spnego_log_krb5_error(kcontext, code);
spnego_error(NGX_ERROR);
Expand Down