krb5 commit: Avoid asymmetric WSACleanup() in libkrb5
[email protected] Wed, 27 May 2026 18:53:00 -0400 (EDT)
| Newsgroups | gmane.comp.encryption.kerberos.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://github.com/krb5/krb5/commit/acf38f87c07f873c13ec2f51442519e16f1c3512 commit acf38f87c07f873c13ec2f51442519e16f1c3512 Author: Greg Hudson <[email protected]> Date: Mon May 18 12:27:52 2026 -0400 Avoid asymmetric WSACleanup() in libkrb5 In k5_os_init_context(), call WSAStartup() before doing anything else. Otherwise, a failure to read or parse krb5.conf could cause an asymmetric call to WSACleanup() in k5_os_free_context(). Reported by Zvika Meiseles. ticket: 9210 (new) tags: pullup target_version: 1.22-next src/lib/krb5/os/init_os_ctx.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index c35007888..2d9951186 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -416,8 +416,11 @@ k5_os_init_context(krb5_context ctx, profile_t profile, krb5_flags flags) krb5_os_context os_ctx; krb5_error_code retval = 0; #ifdef _WIN32 - WORD wVersionRequested; WSADATA wsaData; + + /* Initialize winsock to version 1.1. Do this first so that we know it was + * done in k5_os_free_context(), and can safely call WSACleanup(). */ + WSAStartup(0x0101, &wsaData); #endif /* _WIN32 */ os_ctx = &ctx->os_context; @@ -438,14 +441,6 @@ k5_os_init_context(krb5_context ctx, profile_t profile, krb5_flags flags) if (retval) return retval; -#ifdef _WIN32 - /* We initialize winsock to version 1.1 but - * we do not care if we succeed or fail. - */ - wVersionRequested = 0x0101; - WSAStartup (wVersionRequested, &wsaData); -#endif /* _WIN32 */ - return 0; }