Skip to content

Commit ecd3d51

Browse files
committed
Fix: issue with freeing static krb5 OID
1 parent b916c78 commit ecd3d51

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

misc/openvas-krb5.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ okrb5_gss_free_context (struct OKrb5GSSContext *context)
420420
{
421421
gss_release_name (&min_stat, &context->gss_target);
422422
}
423-
if (context->gss_mech != NULL)
423+
// This context is set statically and should not be freed
424+
if (context->gss_mech != NULL && context->gss_mech != gss_mech_spnego)
424425
{
425426
gss_release_oid (&min_stat, &context->gss_mech);
426427
}

rust/src/nasl/builtin/krb5/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use nasl_c_lib::krb5::{
1111
OKrb5ErrorCode_O_KRB5_EXPECTED_NOT_NULL, OKrb5ErrorCode_O_KRB5_REALM_NOT_FOUND,
1212
OKrb5ErrorCode_O_KRB5_SUCCESS, OKrb5GSSContext, OKrb5Slice, OKrb5Target, OKrb5User,
1313
o_krb5_add_realm, o_krb5_find_kdc, o_krb5_gss_prepare_context, o_krb5_gss_session_key_context,
14-
o_krb5_gss_update_context, okrb5_error_code_to_string, okrb5_gss_init_context,
14+
o_krb5_gss_update_context, okrb5_error_code_to_string, okrb5_gss_free_context,
15+
okrb5_gss_init_context,
1516
};
1617
use nasl_function_proc_macro::nasl_function;
1718
use std::os;
@@ -190,20 +191,15 @@ impl Drop for Krb5 {
190191
}
191192
}
192193

193-
// TODO: This block leads to munmap_chunk(): invalid pointer and Aborted (core dumped)
194-
// let cached_gss_context = *self.cached_gss_context.lock().unwrap();
195-
// if !cached_gss_context.is_null() {
196-
// unsafe {
197-
// okrb5_gss_free_context(cached_gss_context);
198-
// }
199-
// }
194+
let cached_gss_context = *self.cached_gss_context.lock().unwrap();
195+
if !cached_gss_context.is_null() {
196+
unsafe {
197+
okrb5_gss_free_context(cached_gss_context);
198+
}
199+
}
200200
}
201201
}
202202

203-
// SAFETY: Krb5 can be safely sent between threads because:
204-
// - The raw pointers are stored behind Arc<Mutex<...>> for synchronization
205-
// - Access to the pointers is guarded by mutex locks
206-
// - The outer Arc<Mutex<...>> provides the thread-safe coordination
207203
unsafe impl Send for Krb5 {}
208204
unsafe impl Sync for Krb5 {}
209205

0 commit comments

Comments
 (0)